﻿'''' Last modified on Dec 04, 2014 15.00 น.

Imports System.Data
Imports System.Data.OleDb
Imports ADOEntityKYC
Partial Class KYC_IndividualKYC
    Inherits Web.UI.BasePage

#Region " Variable Gobal "

    Dim cn As New OleDbConnection
    Dim clsDatabase As New clsDatabase
    Dim Sql As String
    Dim ds As DataSet
    Dim TypeKYC As Integer = 0
    Dim CustSeq As Integer = 0
    Dim KYCEntity As KYCEntities = New KYCEntities
    Dim clsSessionMenuRight As clsSessionMenuRight = New clsSessionMenuRight
    Dim strMsg As String = ""
    Dim clsDateFormat As clsDateFormat
    Dim strCddOld As Integer
    Dim strCdd As Integer
    Dim clsDataTable As New clsLINQToDataTable
    Dim intBeforeItemIndex As Integer = -1
    Dim clsMoney As clsMoney
    Dim condition As Boolean = True
    Dim acc As String
    Public CBSAddress_Visable As String = ""
    Public KYCAddress_Visable As String = ""
    Dim intCountSearch As Integer = 0
    ''''Prachak ''''''''''''''''
    Dim clsValid As clsValidateData
    Dim lvsSQL As String

    ''''offer Script''''
    Dim indexGrdAddrNationBefore As Int32 = -1
    Dim indexGrdBoBefore As Int32 = -1
    Dim indexGrdOccDetailBefore As Int32 = -1
    Dim indexGrdDAccBefore As Int32 = -1
    Dim indexGrdDSourceBefore As Int32 = -1
    Dim indexGrdLAccBefore As Int32 = -1
    Dim indexGrdPAccBefore As Int32 = -1
    Dim indexGrdPSourceBefore As Int32 = -1
    Dim indexGrdFamilyBefore As Int32 = -1
    Dim indexGrdReasonBefore As Int32 = -1
    ''''End offer Script''''
#End Region

#Region "Even Page"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        clsValid = New clsValidateData()

        Try
    

            Me.Initial_Screen()
            'Me.TxtAccNo.Enabled = True
            'Me.btAddAcc.Enabled = True

            ''''offer Script''''
            lbCUSTSEQ.Text = Request.QueryString("CUSTSEQ")
            lbCUSTTYPE.Text = Request.QueryString("KYC")

            btAddBo.Attributes.Add("onClick", "OpenBo('add');")   ''''showModalDialog
            btEditBo.Attributes.Add("onClick", "OpenBo('edit');")   ''''showModalDialog
            ''''End offer Script''''

            TypeKYC = Request.QueryString("TypeKYC")
            CustSeq = Request.QueryString("CUSTSEQ")

            acc = Request.QueryString("acc")
            'strCdd = Request.QueryString("CDD")
            ds = Session("ds")
            clsSessionMenuRight = Session("clsMenuRight")

            If Not TypeKYC = 4 Then
                btnCancel.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resMsgKYC.msgCancle) + "')")
                btnCDD.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resMsgKYC.msgBtnCDD) + "')")

            Else
                ' btnCDD.Visible = False
            End If

            If Not IsPostBack Then
                Session("CUSTSEQ") = Nothing

                chkIsLogin()
                CreateControlMP()

                loadDataToDropDown()

                If Not CustSeq = 0 Then

                    BindingDataCBS()
                    If Request.QueryString("KYC") <> 5 Then
                        Me.Find_SmartCard_for_Address(Me.txtUniqueID.Text)
                        Me.loadKYCAccount()
                        ''''offer Script''''
                        loadNation()
                        loadAddrNation()
                        loadPassport()
                        loadOtherID()
                        loadPolitical()
                        loadIncome()
                        loadOcc()
                        loadBo(CustSeq)

                        If (Request.QueryString("KYC") = 1) Then
                            loadDObj(grdDAcc)
                            loadDsource(grdDSource)
                        ElseIf (Request.QueryString("KYC") = 2) Then
                            loadDObj(grdLAcc)
                        ElseIf (Request.QueryString("KYC") = 3) Then
                            loadDObj(grdPAcc)
                            loadDsource(grdPSource)
                        End If
                        'loadFamily()
                        'loadReason()
                        ''''end offer Script''''
                    End If

                    'strCdd = hdfCdd.Value
                    'strCddOld = hdfCddOld.Value

                    indexOccupationChanging2()
                    indexOccupationChanging3()

                    indexBizChanging2()
                    indexBizChanging3()

                Else
                    loadDataAddr("", "", "", 1)
                    loadDataAddr("", "", "", 2)
                    loadDataAddr("", "", "", 3)
                End If
            Else
                'strCdd = hdfCdd.Value
                'strCddOld = hdfCddOld.Value
            End If

            ' ---- Edit Boy ----
            SetControlAddress()

            If hdfCdd.Value = "" Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                       UpdatePanel1.GetType(), _
                                                       "clientScript", _
                                                       "alert('" + "กรุณาประเมินความเสี่ยงก่อน" + "')", _
                                                       True)
                hdfCdd.Value = 0
            End If

            strCdd = hdfCdd.Value
            strCddOld = hdfCddOld.Value
            VisbleKYC()
            EnableKYC()
            If (grdShowAccount.SelectedIndex > -1) Then
                btnSave.Visible = True
            End If

            If strCdd = 0 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + "กรุณาประเมินความเสี่ยงก่อน" + "')", _
                                                            True)
            End If
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try

    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        Session("ds") = ds
    End Sub

#End Region

#Region "SetForm"

    Sub CreateControlMP()
        Dim img As Image = CType(Master.FindControl("imgHead"), Image)
        img.ImageUrl = "~/img/Individual.jpg"

        Dim page As Label = CType(Master.FindControl("lblPage"), Label)
        page.Text = "ข้อมูล KYC"
    End Sub

    Private Sub VisbleKYC()

        'If Request.QueryString("KYC") = 1 Then
        '    PanelDepositSactionC.Visible = True
        '    PanelLoanSactionC.Visible = False
        '    PanelPNSactionC.Visible = False
        'ElseIf Request.QueryString("KYC") = 2 Then
        '    PanelDepositSactionC.Visible = True
        '    PanelLoanSactionC.Visible = False
        '    PanelPNSactionC.Visible = False
        'ElseIf Request.QueryString("KYC") = 3 Then
        '    PanelDepositSactionC.Visible = True
        '    PanelLoanSactionC.Visible = False
        '    PanelPNSactionC.Visible = False
        'Else
        '    PanelDepositSactionC.Visible = True
        '    PanelLoanSactionC.Visible = True
        '    PanelPNSactionC.Visible = True

        '    btnEdit.Visible = False
        '    btnFinish.Visible = False
        'End If


        Dim intCdd As Integer = hdfCdd.Value

        If Request.QueryString("KYC") = 1 Then
            PanelDeposit.Visible = True
            PanelLoan.Visible = False
            PanelPN.Visible = False
            'เพิ่มเติม

            'If Not hdfApproveCode.Value = 0 Then
            '    PanelDepositSactionC.Visible = True
            'Else
            '    PanelDepositSactionC.Visible = False
            'End If
            ' PanelLoanSactionC.Visible = False
            ' PanelPNSactionC.Visible = False
            '-----
        ElseIf Request.QueryString("KYC") = 2 Then
            PanelDeposit.Visible = False
            PanelLoan.Visible = True
            PanelPN.Visible = False
            btnSave.Visible = True
            'เพิ่มเติม
            'If Not hdfApproveCode.Value = 0 Then

            '    PanelDepositSactionC.Visible = True
            'Else
            '    PanelDepositSactionC.Visible = False
            'End If
            '  PanelLoanSactionC.Visible = False
            '  PanelPNSactionC.Visible = False
            '-----
        ElseIf Request.QueryString("KYC") = 3 Then
            PanelDeposit.Visible = False
            PanelLoan.Visible = False
            PanelPN.Visible = True
            'เพิ่มเติม
            'If Not hdfApproveCode.Value = 0 Then
            '    PanelDepositSactionC.Visible = True
            'Else
            '    PanelDepositSactionC.Visible = False
            'End If
            '   PanelLoanSactionC.Visible = False
            '  PanelPNSactionC.Visible = False
            '------
        ElseIf Request.QueryString("KYC") = 5 Then
            PanelAccount.Visible = False
            PanelDeposit.Visible = False
            PanelLoan.Visible = False
            PanelPN.Visible = False
            btnSave.Visible = True

            'เพิ่มเติม
            'If Not hdfApproveCode.Value = 0 Then
            '    PanelDepositSactionC.Visible = True
            'Else
            '    PanelDepositSactionC.Visible = False
            'End If
            '   PanelLoanSactionC.Visible = False
            '  PanelPNSactionC.Visible = False
            '------
        Else
            PanelAccount.Visible = False
            PanelDeposit.Visible = False
            PanelLoan.Visible = False
            PanelPN.Visible = False
            'เพิ่มเติม
            '  PanelDepositSactionC.Visible = True
            ' PanelLoanSactionC.Visible = True
            '   PanelPNSactionC.Visible = True
            '------
            'btnEdit.Visible = False
        End If
    End Sub

    Private Sub EnableKYC()


        If TypeKYC = 4 Then
            PanelDeposit.Enabled = False
            PanelLoan.Enabled = False
            PanelPN.Enabled = False
            Panel1.Enabled = False
            btnEdit.Visible = True

            btnSave.Visible = False

            '    PanelDepositSactionC.Visible = setVisiblePnlApp()
            txtDApproveDate.Visible = False
            txtApproveDate.Visible = True
            '  setApprove()

        Else
            PanelDeposit.Enabled = True
            PanelLoan.Enabled = True
            PanelPN.Enabled = True

            btnEdit.Visible = False
            btnSave.Visible = False


            '   PanelDepositSactionC.Visible = setVisiblePnlApp()
            txtDApproveDate.Visible = True
            txtApproveDate.Visible = False
            ''  setApprove()
        End If
        If Request.QueryString("KYC") = 5 Then
            btnSave.Visible = True

        End If

    End Sub

    Private Sub EnableKYC(ByVal strTypeKYC As Integer)


        If strTypeKYC = 4 Then
            PanelDeposit.Enabled = False
            PanelLoan.Enabled = False
            PanelPN.Enabled = False
            Panel1.Enabled = False
            btnEdit.Visible = True

            btnSave.Visible = False

            PanelDepositSactionC.Visible = setVisiblePnlApp()
            txtDApproveDate.Visible = False
            txtApproveDate.Visible = True

            ' setApprove()

        Else
            PanelDeposit.Enabled = True
            PanelLoan.Enabled = True
            PanelPN.Enabled = True

            btnEdit.Visible = False
            btnSave.Visible = True


            PanelDepositSactionC.Visible = setVisiblePnlApp()
            txtDApproveDate.Visible = True
            txtApproveDate.Visible = False
            '   setApprove()

        End If
        If Request.QueryString("KYC") = 5 Then
            btnSave.Visible = True

        End If
    End Sub

    Private Sub ClearField_OccDetail()
        txtWorkAddress.Text = ""
        txtWorkMoo.Text = ""
        txtWorkStreet.Text = ""
        txtWorkSoi.Text = ""
        txtWorkBuilding.Text = ""
        ddlWorkProvice.SelectedIndex = -1
        ddlWorkAmphor.SelectedIndex = -1
        ddlWorkTambol.SelectedIndex = -1
        txtWorkPostCode.Text = ""
        txtWorkPhone1_1.Text = ""
        txtWorkPhone2_2.Text = ""
        txtWorkPhone3_3.Text = ""
        txtWorkFax1_1.Text = ""
        'btEditOccDetail.Enabled = False
        'btDeleteOccDetail.Enabled = False
    End Sub

    Private Sub ClearFieldNation()
        Me.lbNATION_NAME.Text = ""
        grdAddrNation.SelectedIndex = -1
        txtADDRESS_1_Nation.Text = ""
        txtADDRESS_2_Nation.Text = ""
        txtPHONE1_Nation.Text = ""
        txtPHONE2_Nation.Text = ""
        txtPHONE3_Nation.Text = ""
        txtFAX_Nation.Text = ""
        'Me.btEditNation.Enabled = False
        'Me.btDeleteNation.Enabled = False
    End Sub

    Private Sub ClearFieldBo()
        grdBo.SelectedIndex = -1
        lbACCOUNTNO.Text = ""
        lbCIF_NO.Text = ""
        lbUNIQUEID.Text = ""
        lbPASSPORT_NO.Text = ""
        lbTHFIRSTNAME.Text = ""
        lbTHMIDNAME.Text = ""
        lbTHLASTNAME.Text = ""
        lbACC_OWN_RELATION.Text = ""
        lbRISK_LEVEL.Text = ""
        lbFILTER_RESULT.Text = ""
        lbSEQ.Text = ""
        Me.btDelBo.Enabled = False
    End Sub



#End Region

    Public Function setVisiblePnlApp() As Boolean
        Dim result As Boolean = False

        'strCdd --> ความเสี่ยงปัจจุบัน
        'strCddOld --> ความเสี่ยงอดีต
        'ความเสี่ยงเป็น 2,3,3-->2,3-->1 ต้องโชว์ panal approve
        '
        If strCdd = 0 Then
            result = False
        Else

            If strCdd = 3 Then
                result = True
            ElseIf strCdd = 2 Then
                result = True
            ElseIf strCdd = 1 Then
                If (strCddOld = 2 Or strCddOld = 3) Then
                    result = True
                End If
            End If
        End If




        Return result
    End Function

#Region "Event Dropdrown"


    Protected Sub ddlOccupation2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOccupation2.SelectedIndexChanged
        indexOccupationChanging2()
    End Sub

    Protected Sub ddlBusiness2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBusiness2.SelectedIndexChanged
        indexBizChanging2()
    End Sub

    Protected Sub ddlOccupation3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOccupation3.SelectedIndexChanged
        indexOccupationChanging3()
    End Sub

    Protected Sub ddlBusiness3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBusiness3.SelectedIndexChanged
        indexBizChanging3()
    End Sub

    Protected Sub ddlPrefixTH_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixTH.SelectedIndexChanged
        ddlPrefixEN.SelectedValue = ddlPrefixTH.SelectedValue
    End Sub

    Protected Sub ddlPrefixEN_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixEN.SelectedIndexChanged
        ddlPrefixTH.SelectedValue = ddlPrefixEN.SelectedValue
    End Sub

#End Region

#Region "Event Button"

    Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Try
            Response.Redirect("IndividualKYC.aspx?KYC=" & Request.QueryString("KYC") & "&TypeKYC=3&CUSTSEQ=" & Request.QueryString("CUSTSEQ") & "&CDD=" & strCdd & "")
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Try
            If Not TypeKYC = 4 Then
                If checkBeforeSave() = True Then
                    saveData()
                    SaveLog(4)
                    Response.Redirect("IndividualSectionC.aspx?KYC=" & Request.QueryString("KYC") & "&TypeKYC=" & TypeKYC & "&CUSTSEQ=" & CustSeq & "&CDD=" & strCdd & "")
                Else
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)
                End If
            Else
                Response.Redirect("IndividualSectionC.aspx?KYC=" & Request.QueryString("KYC") & "&TypeKYC=" & TypeKYC & "&CUSTSEQ=" & CustSeq & "&CDD=" & strCdd & "")
            End If
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            Dim dupAccount As Boolean
            Dim countDup As Integer
            dupAccount = False
            countDup = 0
            'If Not (ds.Tables("RKYC") Is Nothing) Then
            '    For i As Integer = 0 To ds.Tables("RKYC").Rows.Count - 1

            '        If TxtAccNo.Text = ds.Tables("RKYC").Rows(i).Item("ACCOUNTNO").ToString Then
            '            If Not (grdShowAccount.SelectedIndex = i) Then
            '                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & " เลขที่บัญชีซ้ำ " & "')", True)
            '                dupAccount = True
            '            End If

            '        End If
            '    Next

            'End If


            'If Not dupAccount Then
            '    If Not (ds.Tables("RKYC") Is Nothing) Then
            '        If ds.Tables("RKYC").Rows.Count > 0 Then
            '            If grdShowAccount.SelectedIndex > -1 Then
            '                Dim strUpdateby As String = grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(6).Text.Trim
            '                Dim strBranch As String = grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(7).Text.Trim
            '                If Not (strUpdateby.Substring(0, 3) = "ETL") Then
            '                    If Not (clsSessionMenuRight.getBranchCode = strBranch) Then

            '                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & "ไม่สามารถบันทึกข้อมูลต่างสาขาได้" & "')", True)
            '                        Exit Sub
            '                    End If
            '                End If
            '            Else
            '                If Request.QueryString("KYC") <> 2 Then
            '                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & "โปรดเลือกรายการ" & "')", True)
            '                    Exit Sub
            '                End If

            '            End If
            '        End If

            '    End If

            Me.TxtAccNo.Enabled = True

            If Request.QueryString("CUSTSEQ") = 0 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgCDD & "')", True)
                Exit Sub
            Else
                If Not TypeKYC = 4 Then
                    If Request.QueryString("KYC") = 5 Then
                        hdfKYCSeq.Value = "0"
                    End If
                    If Not hdfKYCSeq.Value = Nothing Then
                        If Request.QueryString("KYC") = 5 Then
                            If checkNpaSave() = True Then
                                saveNPA()
                                SaveLog(4)
                                ScriptManager.RegisterStartupScript(Me, Me.GetType(), "message", _
                                              "alert('" + Resources.resMsgKYC.msgSave + "');location.href = 'IndividualKYC.aspx?KYC=" &
                                              Request.QueryString("KYC") & "&TypeKYC=4&CUSTSEQ=" &
                                              CustSeq & "&CDD=" & strCdd & "&SelectGrd=" & 0 & "';", True)

                            Else
                                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)
                            End If
                        Else
                            If checkBeforeSave() = True Then   ''''Prachak
                                Dim intAmlCdd As Integer = hdfCdd.Value

                                If PanelDepositSactionC.Visible = True Then
                                    If checkApprove() = False Then
                                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)
                                        Exit Sub
                                    End If
                                End If
                                Call txtDValue_TextChanged(sender, e)

                                If condition = False Then
                                    condition = True
                                    Exit Sub
                                End If
                                ''''Prachak ''''''''''''''''''''''''''''''''
                                If Validate_For_All() = False Then Exit Sub
                                ''''''''''''''''''''''''''''''''''''''''''''
                                saveData() '''' 
                                SaveLog(4)
                                Dim intSelectGrid As Integer = grdShowAccount.SelectedIndex
                                ' EnableKYC(TypeKYC)
                                ScriptManager.RegisterStartupScript(Me, Me.GetType(), "message", _
                                         "alert('" + Resources.resMsgKYC.msgSave + "');location.href = 'IndividualKYC.aspx?KYC=" & Request.QueryString("KYC") & "&TypeKYC=4&CUSTSEQ=" & CustSeq & "&CDD=" & strCdd & "&SelectGrd=" & intSelectGrid & "';", True)
                                '     Response.Redirect("IndividualSearch.aspx?KYC=" & Request.QueryString("KYC") & "&CustSeq=" & CustSeq & "")

                            Else

                                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)
                            End If
                        End If


                    Else
                        If Request.QueryString("KYC") = 2 Then

                            If checkNpaSave() = True Then

                                saveNPA()
                                SaveLog(4)
                                ScriptManager.RegisterStartupScript(Me, Me.GetType(), "message", _
            "alert('" + Resources.resMsgKYC.msgSave + "');location.href = 'IndividualKYC.aspx?KYC=" & Request.QueryString("KYC") & "&TypeKYC=4&CUSTSEQ=" & CustSeq & "&CDD=" & strCdd & "&SelectGrd=" & 0 & "';", True)
                            Else
                                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)
                            End If


                        Else
                            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & " กรุณาเลือกเลขที่บัญชี " & "')", True)

                        End If


                    End If

                Else
                    Response.Redirect("IndividualSearch.aspx?KYC=" & Request.QueryString("KYC") & "&CustSeq=" & CustSeq & "")
                End If
            End If




        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try

    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("IndividualSearch.aspx?KYC=" & Request.QueryString("KYC") & "&CustSeq=" & CustSeq & "")
    End Sub

#End Region

#Region "Function"

    Private Sub loadDataToDropDown()
        Try
            Dim clsDropDown As New clsMasterDropDown

            clsDropDown.setIDTypeToDdl(ddlUniqueType)
            clsDropDown.setPrefixTHToDdl(ddlPrefixTH, 1)
            clsDropDown.setPrefixENToDdl(ddlPrefixEN, 1)
            clsDropDown.setNationalityToDdl(ddlNationality)
            clsDropDown.setBusinessToDdl(ddlBusiness1)
            clsDropDown.setOccupationToDdl(ddlOccupation2, 1)
            clsDropDown.setBusinessToDdl(ddlBusiness2)
            clsDropDown.setOccupationToDdl(ddlOccupation3, 1)
            clsDropDown.setBusinessToDdl(ddlBusiness3)
            clsDropDown.setCountyToDdl(ddlIncomeSource1)
            clsDropDown.setCountyToDdl(ddlIncomeSource2)
            clsDropDown.setCountyToDdl(ddlIncomeSource3)

            clsDropDown.setGenderToDdl(ddlGender)
            clsDropDown.setMaritalToDdl(ddlStatus)

            clsDropDown.setCheckToDdl(ddlCheckName, 1, 0)
            clsDropDown.setCheckToDdl(ddlCheckAddress, 2, 0)

            clsDropDown.setApproveToDdl(ddlDApprove)

            ''''Prachak Dropdown Province
            clsDropDown.setProvince(Me.ddlIDC_PROVINCE)
            clsDropDown.setProvince(Me.ddlKYC_PROVINCE)


            clsDropDown = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub loadDataAddr(ByVal province As String, ByVal amphor As String, ByVal tambol As String, ByVal statusAddr As String)
        Dim clsDropDown As New clsMasterDropDown
        If (statusAddr = 1) Then 'formal
            If province = "" Then
                clsDropDown.setProvince(ddlFormalProvince)
            Else
                clsDropDown.setProvince(ddlFormalProvince, province)
                If Not (ddlFormalProvince.SelectedIndex = 0) Then
                    clsDropDown.setAmphor(ddlFormalAmphor, province, amphor)

                End If
                If Not (ddlFormalProvince.SelectedIndex = 0) Then
                    clsDropDown.setTambol(ddlFormalTambol, amphor, tambol)
                End If

            End If
        ElseIf (statusAddr = 2) Then 'work
            If province = "" Then
                clsDropDown.setProvince(ddlWorkProvice)
            Else
                clsDropDown.setProvince(ddlWorkProvice, province)

                If Not (ddlWorkProvice.SelectedIndex = 0) Then
                    clsDropDown.setAmphor(ddlWorkAmphor, province, amphor)
                End If

                If Not (ddlWorkProvice.SelectedIndex = 0) Then
                    clsDropDown.setTambol(ddlWorkTambol, amphor, tambol)
                End If

            End If
        ElseIf (statusAddr = 3) Then 'contact
            If province = "" Then
                clsDropDown.setProvince(ddlCONTACTPROVINCE)
            Else
                clsDropDown.setProvince(ddlCONTACTPROVINCE, province)
                If Not (ddlCONTACTPROVINCE.SelectedIndex = 0) Then
                    clsDropDown.setAmphor(ddlCONTACTAMPHOR, province, amphor)
                End If
                If Not (ddlCONTACTPROVINCE.SelectedIndex = 0) Then
                    clsDropDown.setTambol(ddlCONTACTTAMBOL, amphor, tambol)
                End If

            End If
        ElseIf (statusAddr = 4) Then 'contact
            If province = "" Then
                clsDropDown.setProvince(ddlTBR_Province)
            Else
                clsDropDown.setProvince(ddlTBR_Province, province)
                If Not (ddlTBR_Province.SelectedIndex = 0) Then
                    clsDropDown.setAmphor(ddlTBR_Amphor, province, amphor)
                End If
                If Not (ddlTBR_Province.SelectedIndex = 0) Then
                    clsDropDown.setTambol(ddlTBR_Tambol, amphor, tambol)
                End If

            End If

        End If


    End Sub


    Private Sub BindingDataCBS() 'ข้อมูลพื้นฐานลูกค้า 
        Try
            Dim convertDate As clsDateFormat = New clsDateFormat

            Dim qryA = (From cust In KYCEntity.MCUSTOMER _
                                    Where cust.CUSTSEQ = CustSeq
                                    Select cust).ToList

            If qryA(0).CUSTCODE = Nothing Then
                lblCIF_CBS_NO.Text = "เลขประจำตัวลูกค้า : -"
            Else
                lblCIF_CBS_NO.Text = "เลขประจำตัวลูกค้า : " + qryA(0).CUSTCODE.ToString
            End If

            If Not qryA(0).THPREFIX Is Nothing Then
                ddlPrefixTH.SelectedValue = qryA(0).THPREFIX
            End If

            ''''Prachak '''''''''''''''''''''''''''''

            Me.lblCIF_CBS_NO.Text = qryA(0).CIF_CBS_NO
            Me.lblCIF_FDR_NO.Text = qryA(0).CIF_FDR_NO
            Me.lblCIF_NPA_NO.Text = qryA(0).CIF_NPA_NO

            Me.lblFILTER_RESULT_CUST.Text = qryA(0).FILTER_RESULT
            Me.lblRISK_LEVEL_CUST.Text = qryA(0).RISK_LEVEL

            ''''Formal Address 26 '''''''''''''''''''''
            Me.txtFORMALADDR.Text = qryA(0).FORMALADDR
            Me.txtFORMALMOO.Text = qryA(0).FORMALMOO
            Me.txtFORMALSTREETDESC.Text = qryA(0).FORMALSTREETDESC
            Me.txtFormalBuilding.Text = qryA(0).FORMALBUILDING
            Me.ddlFormalProvince.Text = qryA(0).FORMALPROVINCE
            Me.ddlFormalAmphor.Text = qryA(0).FORMALAMPHOR
            Me.ddlFormalTambol.Text = qryA(0).FORMALTAMBOL
            Me.txtFORMALZIP.Text = qryA(0).FORMALZIP
            Me.txtFORMALLOCALITY.Text = qryA(0).FORMALLOCALITY
            Me.txtFORMALPHONE1.Text = qryA(0).FORMALPHONE1
            Me.txtFORMALPHONE2.Text = qryA(0).FORMALPHONE2
            Me.txtFORMALPHONE3.Text = qryA(0).FORMALPHONE3
            Me.txtFORMALFAX.Text = qryA(0).FORMALFAX

            ''''IDC Address 27''''''''''''''''''''''''''''
            'Me.txtIDC_BUILDING.Text = qryA(0).IDC_BUILDING
            'Me.txtIDC_FLOOR.Text = qryA(0).IDC_FLOOR
            'Me.txtIDC_DIV_CONT.Text = qryA(0).IDC_DIV_CONT
            Me.txtIDC_ADDR.Text = qryA(0).IDC_ADDR
            Me.txtIDC_MOO.Text = qryA(0).IDC_MOO
            Me.txtIDC_SOIDESC.Text = qryA(0).IDC_SOIDESC
            Me.txtIDC_STREETDESC.Text = qryA(0).IDC_STREETDESC
            Me.txtIDC_LOCALITY.Text = qryA(0).IDC_LOCALITY
            Me.txtIDC_ZIP.Text = qryA(0).IDC_ZIP
            Me.txtIDC_PHONE1.Text = qryA(0).IDC_PHONE1
            Me.txtIDC_PHONE2.Text = qryA(0).IDC_PHONE2
            Me.txtIDC_PHONE3.Text = qryA(0).IDC_PHONE3
            Me.txtIDC_FAX.Text = qryA(0).IDC_FAX

            ''''TBR Address 28''''''''''''''''''''''''''''
            Me.txtTBR_BUILDING.Text = qryA(0).TBR_BUILDING
            Me.txtTBR_FLOOR.Text = qryA(0).TBR_FLOOR
            Me.txtTBR_DIV_CONT.Text = qryA(0).TBR_DIV_CONT
            Me.txtTBR_ADDR.Text = qryA(0).TBR_ADDR
            Me.txtTBR_MOO.Text = qryA(0).TBR_MOO
            Me.txtTBR_SOIDESC.Text = qryA(0).TBR_SOIDESC
            Me.txtTBR_STREETDESC.Text = qryA(0).TBR_STREETDESC
            Me.txtTBR_LOCALITY.Text = qryA(0).TBR_LOCALITY
            Me.txtTBR_ZIP.Text = qryA(0).TBR_ZIP
            Me.txtTBR_PHONE1.Text = qryA(0).TBR_PHONE1
            Me.txtTBR_PHONE2.Text = qryA(0).TBR_PHONE2
            Me.txtTBR_PHONE3.Text = qryA(0).TBR_PHONE3
            Me.txtTBR_FAX.Text = qryA(0).TBR_FAX

            'Me.txtCONTACTBUILDING.Text = qryA(0).CONTACTBUILDING
            'Me.txtCONTACTFLOOR.Text = qryA(0).CONTACTFLOOR
            'Me.txtCONTACTDIV_CONT.Text = qryA(0).CONTACTDIV_CONT
            Me.txtCONTACTADDR.Text = qryA(0).CONTACTADDR
            Me.txtCONTACTMOO.Text = qryA(0).CONTACTMOO
            Me.txtCONTACTSOIDESC.Text = qryA(0).CONTACTSOIDESC
            Me.txtCONTACTSTREETDESC.Text = qryA(0).CONTACTSTREETDESC
            Me.txtCONTACTLOCALITY.Text = qryA(0).CONTACTLOCALITY
            Me.txtCONTACTZIP.Text = qryA(0).CONTACTZIP
            Me.txtCONTACTPHONE1.Text = qryA(0).CONTACTPHONE1
            Me.txtCONTACTPHONE2.Text = qryA(0).CONTACTPHONE2
            Me.txtCONTACTPHONE3.Text = qryA(0).CONTACTPHONE3
            Me.txtCONTACTFAX.Text = qryA(0).CONTACTFAX

            ''''KYC Address 30''''''''''''''''''''''''''''
            Me.txtKYC_BUILDING.Text = qryA(0).KYC_BUILDING
            Me.txtKYC_FLOOR.Text = qryA(0).KYC_FLOOR
            Me.txtKYC_DIV_CONT.Text = qryA(0).KYC_DIV_CONT
            Me.txtKYC_ADDR.Text = qryA(0).KYC_ADDR
            Me.txtKYC_MOO.Text = qryA(0).KYC_MOO
            Me.txtKYC_SOIDESC.Text = qryA(0).KYC_SOIDESC
            Me.txtKYC_STREETDESC.Text = qryA(0).KYC_STREETDESC
            Me.txtKYC_LOCALITY.Text = qryA(0).KYC_LOCALITY
            Me.txtKYC_ZIP.Text = qryA(0).KYC_ZIP
            Me.txtKYC_PHONE1.Text = qryA(0).KYC_PHONE1
            Me.txtKYC_PHONE2.Text = qryA(0).KYC_PHONE2
            Me.txtKYC_PHONE3.Text = qryA(0).KYC_PHONE3
            Me.txtKYC_FAX.Text = qryA(0).KYC_FAX

            Me.loadDataAddr_KYC(qryA(0).KYC_PROVINCE, qryA(0).KYC_AMPHOR, qryA(0).KYC_TAMBOL)

            ''''Prachak '''''''''''''''''''''''''''''
            Me.lblF_POLITIC.Text = qryA(0).F_POLITIC
            If Me.lblF_POLITIC.Text = "Y" Then
                Me.optPOL_CONNECT_Y.Checked = True
            Else
                Me.optPOL_CONNECT_N.Checked = True
            End If
            ''''''''''''''''''''''''''''''''''''

            Me.txtID_CARD_ISSUE_DATE_TH.Text = qryA(0).ID_CARD_ISSUE_DATE

            If Me.txtID_CARD_ISSUE_DATE_TH.Text <> "" Then
                Me.txtID_CARD_ISSUE_DD.Text = Mid(Me.txtID_CARD_ISSUE_DATE_TH.Text, 1, 2)
                Me.txtID_CARD_ISSUE_MM.Text = Mid(Me.txtID_CARD_ISSUE_DATE_TH.Text, 4, 2)
                Me.txtID_CARD_ISSUE_YYYY.Text = Mid(Me.txtID_CARD_ISSUE_DATE_TH.Text, 7, 4)
                Me.txtID_CARD_ISSUE_DATE_EN.Text = clsValid.ConcatDate(Me.txtID_CARD_ISSUE_DD.Text,
                                                   Me.txtID_CARD_ISSUE_MM.Text,
                                                   CInt(Me.txtID_CARD_ISSUE_YYYY.Text) - 543)

            End If
            ''''''''''''
            Me.txtID_CARD_EXP_DATE_TH.Text = qryA(0).ID_CARD_EXP_DATE

            If Me.txtID_CARD_EXP_DATE_TH.Text <> "" Then
                Me.txtID_CARD_EXP_DD.Text = Mid(Me.txtID_CARD_EXP_DATE_TH.Text, 1, 2)
                Me.txtID_CARD_EXP_MM.Text = Mid(Me.txtID_CARD_EXP_DATE_TH.Text, 4, 2)
                Me.txtID_CARD_EXP_YYYY.Text = Mid(Me.txtID_CARD_EXP_DATE_TH.Text, 7, 4)
                Me.txtID_CARD_EXP_DATE_EN.Text = clsValid.ConcatDate(Me.txtID_CARD_EXP_DD.Text,
                                                   Me.txtID_CARD_EXP_MM.Text,
                                                   CInt(Me.txtID_CARD_EXP_YYYY.Text) - 543)

            End If
            ''''''''''''
            ''''''''''''
            Me.lblFLAG_ID_CARD_WL.Text = qryA(0).FLAG_ID_CARD_WL
            If Me.lblFLAG_ID_CARD_WL.Text = "Y" Then
                Me.chkExpire_None.Checked = True
            Else
                Me.chkExpire_None.Checked = False
            End If
            '''''''''''''''''''''''''''''''''''''''''
            Me.lbBIRTH_DATE_TH.Text = qryA(0).BIRTH_DATE_TH
            Me.txtBIRTH_DATE_TH_DD.Text = (Mid(Me.lbBIRTH_DATE_TH.Text, 1, 2))
            Me.txtBIRTH_DATE_TH_MM.Text = (Mid(Me.lbBIRTH_DATE_TH.Text, 4, 2))
            Me.txtBIRTH_DATE_TH_YYYY.Text = (Mid(Me.lbBIRTH_DATE_TH.Text, 7, 4))


            Me.lbBIRTH_DATE_EN.Text = qryA(0).BIRTH_DATE_EN
            Me.txtBIRTH_DATE_EN_DD.Text = (Mid(Me.lbBIRTH_DATE_EN.Text, 1, 2))
            Me.txtBIRTH_DATE_EN_MM.Text = (Mid(Me.lbBIRTH_DATE_EN.Text, 4, 2))
            Me.txtBIRTH_DATE_EN_YYYY.Text = (Mid(Me.lbBIRTH_DATE_EN.Text, 7, 4))

            txtNameTh1.Text = qryA(0).THFIRSTNAME
            txtNameTh2.Text = qryA(0).THMIDNAME
            txtNameTh3.Text = qryA(0).THLASTNAME
            If Not qryA(0).ENPREFIX Is Nothing Then
                ddlPrefixEN.SelectedValue = qryA(0).ENPREFIX
            End If
            txtNameEn1.Text = qryA(0).ENFIRSTNAME
            txtNameEn2.Text = qryA(0).ENMIDNAME
            txtNameEn3.Text = qryA(0).ENLASTNAME
            If Not qryA(0).CUSTIDTYPE Is Nothing Then
                ddlUniqueType.SelectedValue = qryA(0).CUSTIDTYPE
            End If
            txtUniqueID.Text = qryA(0).UNIQUEID

            txtEvBy.Text = qryA(0).EVBY

            If Not qryA(0).EVGEN Is Nothing Then
                txtEvGen.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryA(0).EVGEN)
                txtEvGen1.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryA(0).EVGEN)
            End If

            If Not qryA(0).EVEXPIRE Is Nothing Then
                txtEvExpire.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryA(0).EVEXPIRE)
                txtEvExpire1.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryA(0).EVEXPIRE)
            Else
                ' chkExpire.Checked = True
            End If

            If Not qryA(0).BIRTHDATE Is Nothing Then
                txtBirth.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryA(0).BIRTHDATE)
                txtBirth1.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryA(0).BIRTHDATE)
            End If

            If Not qryA(0).GENDER = Nothing Then
                ddlGender.SelectedValue = qryA(0).GENDER
            End If
            If Not qryA(0).MARITALSTATUS Is Nothing Then
                ddlStatus.SelectedValue = qryA(0).MARITALSTATUS
            End If
            If Not qryA(0).NATIONALITY Is Nothing Then
                ddlNationality.SelectedValue = qryA(0).NATIONALITY
            End If
            txtOccOther2.Text = qryA(0).OCCUPATIONTYPEOTHER2
            If Not qryA(0).OCCUPATIONTYPE3 Is Nothing Then
                ddlOccupation3.SelectedValue = qryA(0).OCCUPATIONTYPE3
            End If
            txtOccOther3.Text = qryA(0).OCCUPATIONTYPEOTHER3
            If Not qryA(0).BIZTYPE1 Is Nothing Then
                ddlBusiness1.SelectedValue = qryA(0).BIZTYPE1
            End If

            If Not qryA(0).BIZTYPE2 Is Nothing Then
                ddlBusiness2.SelectedValue = qryA(0).BIZTYPE2
            End If
            txtBizOther2.Text = qryA(0).BIZTYPEOTHER2
            If Not qryA(0).BIZTYPE3 Is Nothing Then
                ddlBusiness3.SelectedValue = qryA(0).BIZTYPE3
            End If

            txtBizOther3.Text = qryA(0).BIZTYPEOTHER3

            txtDes1.Text = qryA(0).BIZDESC1
            txtDes2.Text = qryA(0).BIZDESC2
            txtDes3.Text = qryA(0).BIZDESC3

            'txtWorkAddr.Text = qryA(0).WORKADDR
            loadDataAddr(qryA(0).WORKPROVINCE, qryA(0).WORKAMPHOR, qryA(0).WORKTAMBOL, 2)
            txtWorkAddress.Text = qryA(0).WORKNO
            txtWorkMoo.Text = qryA(0).WORKMOO
            txtWorkStreet.Text = qryA(0).WORKSTREET
            txtWorkSoi.Text = qryA(0).WORKSOIDESC
            txtWorkBuilding.Text = qryA(0).WORKBUILDING
            txtWorkPhone1_1.Text = qryA(0).WORKPHONE1
            txtWorkPhone2_2.Text = qryA(0).WORKPHONE2
            txtWorkPhone3_3.Text = qryA(0).WORKPHONE3
            txtWorkFax1_1.Text = qryA(0).WORKFAX
            txtWorkPostCode.Text = qryA(0).WORKZIP


            'txtFormalAddr.Text = qryA(0).FORMALADDR
            'txtFormalPhone1.Text = qryA(0).FORMALPHONE1

            loadDataAddr(qryA(0).FORMALPROVINCE, qryA(0).FORMALAMPHOR, qryA(0).FORMALTAMBOL, 1)

            txtIDC_ADDR.Text = qryA(0).FORMALNO
            txtFORMALMOO.Text = qryA(0).FORMALMOO
            txtFORMALSTREETDESC.Text = qryA(0).FORMALSTREET
            txtFORMALSOIDESC.Text = qryA(0).FORMALSOIDESC
            txtFormalBuilding.Text = qryA(0).FORMALBUILDING
            txtFORMALPHONE1.Text = qryA(0).FORMALPHONE1
            txtFORMALPHONE2.Text = qryA(0).FORMALPHONE2
            txtFORMALPHONE3.Text = qryA(0).FORMALPHONE3
            txtFORMALFAX.Text = qryA(0).FORMALFAX
            txtFORMALZIP.Text = qryA(0).FORMALZIP



            'txtContactAddr.Text = qryA(0).CONTACTADDR

            loadDataAddr(qryA(0).CONTACTPROVINCE, qryA(0).CONTACTAMPHOR, qryA(0).CONTACTTAMBOL, 3)
            txtTBR_ADDR.Text = qryA(0).CONTACTNO
            txtTBR_MOO.Text = qryA(0).CONTACTMOO
            txtTBR_STREETDESC.Text = qryA(0).CONTACTSTREET
            txtTBR_SOIDESC.Text = qryA(0).CONTACTSOIDESC

            'ddlContactProvice.SelectedValue = qryA(0).CONTACTPROVINCE
            'ddlContactAmphor.SelectedValue = qryA(0).CONTACTAMPHOR
            'ddlContactTambol.SelectedValue = qryA(0).CONTACTTAMBOL
            txtTBR_PHONE1.Text = qryA(0).CONTACTPHONE1
            txtTBR_PHONE2.Text = qryA(0).CONTACTPHONE2
            txtTBR_PHONE3.Text = qryA(0).CONTACTPHONE3
            txtTBR_FAX.Text = qryA(0).CONTACTFAX
            txtTBR_ZIP.Text = qryA(0).CONTACTZIP



            If Not qryA(0).INCOMESOURCE1 Is Nothing Then
                ddlIncomeSource1.SelectedValue = qryA(0).INCOMESOURCE1
            End If
            If Not qryA(0).INCOMESOURCE2 Is Nothing Then
                ddlIncomeSource2.SelectedValue = qryA(0).INCOMESOURCE2
            End If
            If Not qryA(0).INCOMESOURCE3 Is Nothing Then
                ddlIncomeSource3.SelectedValue = qryA(0).INCOMESOURCE3
            End If

            If Not qryA(0).CHECKNAME Is Nothing Then
                ddlCheckName.SelectedValue = qryA(0).CHECKNAME
            End If
            If Not qryA(0).CHECKADDRESS Is Nothing Then
                ddlCheckAddress.SelectedValue = qryA(0).CHECKADDRESS
            End If

            Dim riskLevel As String = ""
            riskLevel = "ระดับความเสี่ยงลูกค้า : " + qryA(0).AMLCDD.ToString

            hdfCdd.Value = qryA(0).AMLCDD.ToString
            If qryA(0).AMLCDDBEFORE.ToString = "" Then
                hdfCddOld.Value = 0

            Else
                hdfCddOld.Value = qryA(0).AMLCDDBEFORE.ToString

            End If
            'If qryA(0).AMLCDD > 1 Then
            If Not qryA(0).AMLREASON Is Nothing Then
                riskLevel += " (เหตุผล : " + qryA(0).AMLREASON.ToString + ")"
            End If
            'End If

            If qryA(0).AMLCDD.ToString = "1" Then
                lblRiskLevel.ForeColor = Drawing.Color.Green
            ElseIf qryA(0).AMLCDD.ToString = "2" Then
                lblRiskLevel.ForeColor = Drawing.Color.Orange
            ElseIf qryA(0).AMLCDD.ToString = "3" Then
                lblRiskLevel.ForeColor = Drawing.Color.Red
            End If

            'แก้ตอนประเมินให้ใส่ค่าเริ่มต้นเป็น 0
            'hdfApproveCode.Value = qryA(0).APPROVECODE

            'If Not hdfApproveCode.Value = 0 Then
            '    ddlDApprove.SelectedValue = qryA(0).APPROVECODE
            'End If



            lblRiskLevel.Text = riskLevel

            If Not qryA(0).TRANTYPE Is Nothing Then
                If qryA(0).TRANTYPE = 2 Then 'ลูกค้าขาจร
                    PanelCBS.Enabled = True
                    CustCasual()
                    hdfTranType.Value = 2
                    txtBirth.Visible = False
                    txtEvExpire.Visible = False
                    txtEvGen.Visible = False
                ElseIf Request.QueryString("KYC") = 3 And qryA(0).TRANTYPE = 1 Then
                    PanelCBS.Enabled = True
                    CustCasual()
                    hdfTranType.Value = 2
                    txtBirth.Visible = False
                    txtEvExpire.Visible = False
                    txtEvGen.Visible = False
                Else
                    hdfTranType.Value = 0
                    txtBirth1.Visible = False
                    txtEvExpire1.Visible = False
                    txtEvGen1.Visible = False
                End If
            End If

            convertDate = Nothing
            qryA = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Private Sub loadDataAddr_KYC(ByVal province As String, ByVal amphor As String, ByVal tambol As String)
        Dim clsDropDown As New clsMasterDropDown

        If province = "" Then
            clsDropDown.setProvince(ddlKYC_PROVINCE)
        Else
            clsDropDown.setProvince(ddlKYC_PROVINCE, province)
            If Not (ddlKYC_PROVINCE.SelectedIndex = 0) Then
                clsDropDown.setAmphor(ddlKYC_AMPHOR, province, amphor)

            End If
            If Not (ddlKYC_PROVINCE.SelectedIndex = 0) Then
                clsDropDown.setTambol(ddlKYC_TAMBOL, amphor, tambol)
            End If

        End If

    End Sub

    Private Sub loadDataAddr_SmartCard(ByVal province As String, ByVal amphor As String, ByVal tambol As String)
        Dim clsDropDown As New clsMasterDropDown

        If province = "" Then
            clsDropDown.setProvince(ddlIDC_PROVINCE)
        Else
            clsDropDown.setProvince(ddlIDC_PROVINCE, province)
            If Not (ddlIDC_PROVINCE.SelectedIndex = 0) Then
                clsDropDown.setAmphor(ddlIDC_AMPHOR, province, amphor)

            End If
            If Not (ddlIDC_PROVINCE.SelectedIndex = 0) Then
                clsDropDown.setTambol(ddlIDC_TAMBOL, amphor, tambol)
            End If

        End If

    End Sub
    Private Sub loadPassport()
        Dim clsDataTable As New clsLINQToDataTable
        Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

        If ds.Tables.Contains("MCUST_PASSPORT") Then
            ds.Tables.Remove("MCUST_PASSPORT")
        End If

        Dim qry = From tbl In KYCEntity.MCUST_PASSPORT
                 Where tbl.CUSTSEQ = CustSeq
              Order By tbl.SEQ
                Select tbl.PASSPORT_NO,
                       tbl.ISSUE_DATE,
                       tbl.EXPIRE_DATE,
                       tbl.SEQ,
                       ACTIVE = If(tbl.ACTIVE = "Y", True, False)

        ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_PASSPORT").Copy)
        grdPassport.DataSource = ds.Tables("MCUST_PASSPORT")
        grdPassport.DataBind()
        Me.lblCount_Passport.Text = ds.Tables("MCUST_PASSPORT").Rows.Count
    End Sub

    Private Sub loadNation()
        Dim clsDataTable As New clsLINQToDataTable
        Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

        If ds.Tables.Contains("MCUST_NATION_VIEW") Then
            ds.Tables.Remove("MCUST_NATION_VIEW")
        End If

        Dim qry = From tbl In KYCEntity.MCUST_NATION
                 Where tbl.CUSTSEQ = CustSeq
              Order By tbl.SEQ
                Select tbl.NATION_NAME,
                       tbl.NATIONALITY,
                       tbl.ADDRESS_1,
                       tbl.ADDRESS_2,
                       tbl.PHONE1,
                       tbl.PHONE2,
                       tbl.PHONE3,
                       tbl.FAX,
                       tbl.SEQ,
                       ACTIVE = If(tbl.ACTIVE = "Y", True, False)

        ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_NATION_VIEW").Copy)

        grdNaiton.DataSource = ds.Tables("MCUST_NATION_VIEW")
        grdNaiton.DataBind()
        Me.lblCount_Nation.Text = ds.Tables("MCUST_NATION_VIEW").Rows.Count
    End Sub

    Private Sub loadAddrNation()
        Dim clsDataTable As New clsLINQToDataTable
        Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

        If ds.Tables.Contains("MCUST_NATION") Then
            ds.Tables.Remove("MCUST_NATION")
        End If

        Dim qry = From tbl In KYCEntity.MCUST_NATION
                 Where tbl.CUSTSEQ = CustSeq And tbl.NATIONALITY <> 202
              Order By tbl.SEQ
                Select tbl.NATION_NAME,
                       tbl.NATIONALITY,
                       tbl.ADDRESS_1,
                       tbl.ADDRESS_2,
                       tbl.PHONE1,
                       tbl.PHONE2,
                       tbl.PHONE3,
                       tbl.FAX,
                       tbl.SEQ,
                       ACTIVE = If(tbl.ACTIVE = "Y", True, False)

        ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_NATION").Copy)

        grdAddrNation.DataSource = ds.Tables("MCUST_NATION")
        grdAddrNation.DataBind()
        Me.lblCount_Nation_Address.Text = ds.Tables("MCUST_NATION").Rows.Count
    End Sub

    Private Sub loadOtherID()

        Dim clsDataTable As New clsLINQToDataTable
        Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

        If ds.Tables.Contains("MCUST_OTH_DOC") Then
            ds.Tables.Remove("MCUST_OTH_DOC")
        End If

        Dim qry = From tbl In KYCEntity.MCUST_OTH_DOC
                 Where tbl.CUSTSEQ = CustSeq
              Order By tbl.SEQ
                Select tbl.OTH_DOC_ID,
                       tbl.OTH_DOC_NAME,
                       tbl.OTH_DOC_CARDID,
                       tbl.SEQ,
                       ACTIVE = If(tbl.ACTIVE = "Y", True, False)


        ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_OTH_DOC").Copy)
        grdOtherID.DataSource = ds.Tables("MCUST_OTH_DOC")
        grdOtherID.DataBind()
        Me.lblCount_Oth_Doc.Text = ds.Tables("MCUST_OTH_DOC").Rows.Count
    End Sub

    Private Sub loadPolitical()

        Dim clsDataTable As New clsLINQToDataTable
        Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

        If ds.Tables.Contains("MCUST_POLITICIAN_CONCERN") Then
            ds.Tables.Remove("MCUST_POLITICIAN_CONCERN")
        End If

        Dim qry = From tbl In KYCEntity.MCUST_POLITICIAN_CONCERN
                 Where tbl.CUSTSEQ = CustSeq
              Order By tbl.SEQ
                Select tbl.POLITIC_POST_SELF,
                       tbl.POLITIC_RELATION,
                       tbl.POLITIC_POST_CONC,
                       tbl.THFIRSTNAME,
                       tbl.THMIDNAME,
                       tbl.THLASTNAME,
                       tbl.ENFIRSTNAME,
                       tbl.ENMIDNAME,
                       tbl.ENLASTNAME,
                       tbl.SEQ,
                       ACTIVE = If(tbl.ACTIVE = "Y", True, False)


        ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_POLITICIAN_CONCERN").Copy)
        grdPolitical.DataSource = ds.Tables("MCUST_POLITICIAN_CONCERN")
        grdPolitical.DataBind()
        Me.lblCount_Politic.Text = ds.Tables("MCUST_POLITICIAN_CONCERN").Rows.Count
    End Sub

    Private Sub loadIncome()

        Dim clsDataTable As New clsLINQToDataTable
        Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

        If ds.Tables.Contains("MCUST_INCOME_SOURCE") Then
            ds.Tables.Remove("MCUST_INCOME_SOURCE")
        End If

        Dim qry = From tbl In KYCEntity.MCUST_INCOME_SOURCE
                 Where tbl.CUSTSEQ = CustSeq
              Order By tbl.SEQ
                Select tbl.NATIONCODE,
                       tbl.COUNTYNAME,
                       tbl.SEQ,
                       ACTIVE = If(tbl.ACTIVE = "Y", True, False)

        ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_INCOME_SOURCE").Copy)
        grdIncome.DataSource = ds.Tables("MCUST_INCOME_SOURCE")
        grdIncome.DataBind()
        Me.lblCount_Inc_Source.Text = ds.Tables("MCUST_INCOME_SOURCE").Rows.Count
    End Sub

    Private Sub loadOcc()

        Dim clsDataTable As New clsLINQToDataTable
        Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

        If ds.Tables.Contains("MCUST_OCCUPATION") Then
            ds.Tables.Remove("MCUST_OCCUPATION")
        End If

        Dim qry = From tbl In KYCEntity.MCUST_OCCUPATION
                 Where tbl.CUSTSEQ = CustSeq
              Order By tbl.SEQ
                Select tbl.OCCCODE,
                       tbl.OCC_DESC,
                       tbl.OCCCODE_SUB,
                       tbl.OCC_SUB_DESC,
                       tbl.REMARK_T,
                       tbl.WORKBUILDING,
                       tbl.WORKADDR,
                       tbl.WORKMOO,
                       tbl.WORKSTREET,
                       tbl.WORKSOIDESC,
                       tbl.WORKSTREETDESC,
                       tbl.WORKPROVINCE_CODE,
                       tbl.WORKAMPHOR_CODE,
                       tbl.WORKTAMBOL_CODE,
                       tbl.WORKPROVINCE,
                       tbl.WORKAMPHOR,
                       tbl.WORKTAMBOL,
                       tbl.WORKZIP,
                       tbl.WORKPHONE1,
                       tbl.WORKPHONE2,
                       tbl.WORKPHONE3,
                       tbl.WORKFAX,
                       tbl.POSITION,
                       tbl.SEQ,
                       ACTIVE = If(tbl.ACTIVE = "Y", True, False) ''''_

        '' '', ADDR1 = String.Join(tbl.WORKADDR, " ", tbl.WORKMOO, "", tbl.WORKSOIDESC, "", tbl.WORKSTREETDESC),
        '' ''ADDR2 = String.Join(tbl.WORKTAMBOL, "", tbl.WORKAMPHOR, "", tbl.WORKPROVINCE, "", tbl.WORKZIP)

        ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_OCCUPATION").Copy)

        grdOcc.DataSource = ds.Tables("MCUST_OCCUPATION")
        grdOcc.DataBind()
        Me.lblCount_OCC_Address.Text = ds.Tables("MCUST_OCCUPATION").Rows.Count

        grdOccDetail.DataSource = ds.Tables("MCUST_OCCUPATION")
        grdOccDetail.DataBind()
        Me.lblCount_OCC.Text = ds.Tables("MCUST_OCCUPATION").Rows.Count
    End Sub

    Private Sub loadBo(ByVal lvsCusSeq As Integer)

        Dim clsDataTable As New clsLINQToDataTable
        Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

        If ds.Tables.Contains("MCUST_BO_ACCT") Then
            ds.Tables.Remove("MCUST_BO_ACCT")
        End If

        '''''Where tbl.CUSTSEQ = CustSeq And tbl.ACCOUNTNO = TxtAccNo.Text 

        Dim qry = From tbl In KYCEntity.MCUST_BO_ACCT
                 Where tbl.ACCOUNTNO = TxtAccNo.Text And tbl.CUSTSEQ = lvsCusSeq
              Order By tbl.SEQ
                Select tbl.ACCOUNTNO,
                       tbl.CIF_NO,
                       tbl.UNIQUEID,
                       tbl.PASSPORT_NO,
                       tbl.THFIRSTNAME,
                       tbl.THMIDNAME,
                       tbl.THLASTNAME,
                       tbl.ACC_OWN_RELATION,
                       tbl.RISK_LEVEL,
                       tbl.FILTER_RESULT,
                       tbl.SEQ,
                       ACTIVE = If(tbl.ACTIVE = "Y", True, False)

        ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_BO_ACCT").Copy)

        grdBo.DataSource = ds.Tables("MCUST_BO_ACCT")
        grdBo.DataBind()
        ''''Number of Rows '''''''''''''''''''''
        Me.lblCount_grdBo.Text = ds.Tables("MCUST_BO_ACCT").Rows.Count
        ''''''''''''''''''''''''''''''''''''''''
    End Sub



    'Private Sub loadFamily()
    '    Dim clsDataTable As New clsLINQToDataTable
    '    Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

    '    If ds.Tables.Contains("MCUST_FAMILY") Then
    '        ds.Tables.Remove("MCUST_FAMILY")
    '    End If

    '    Dim qry = From tbl In KYCEntity.MCUST_FAMILY
    '             Where tbl.CUSTSEQ = CustSeq
    '          Order By tbl.SEQ
    '            Select tbl.CIF_NO,
    '                   tbl.UNIQUEID,
    '                   tbl.PASSPORT_NO,
    '                   tbl.THPREFIX,
    '                   tbl.THFIRSTNAME,
    '                   tbl.THMIDNAME,
    '                   tbl.THLASTNAME,
    '                   tbl.ENPREFIX,
    '                   tbl.ENFIRSTNAME,
    '                   tbl.ENMIDNAME,
    '                   tbl.ENLASTNAME,
    '                   tbl.CUST_RELATION,
    '                   tbl.SEQ,
    '                   ACTIVE = If(tbl.ACTIVE = "Y", True, False)

    '    ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_FAMILY").Copy)

    '    grdFamily.DataSource = ds.Tables("MCUST_FAMILY")
    '    grdFamily.DataBind()
    'End Sub

    'Private Sub loadReason()
    '    Dim clsDataTable As New clsLINQToDataTable
    '    Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

    '    If ds.Tables.Contains("MCUST_REASON") Then
    '        ds.Tables.Remove("MCUST_REASON")
    '    End If

    '    Dim qry = From tbl In KYCEntity.MCUST_REASON
    '             Where tbl.CUSTSEQ = CustSeq
    '          Order By tbl.SEQ
    '            Select tbl.USER_CREATED_BY,
    '                   tbl.USER_CREATED_DATE,
    '                   tbl.REASONS,
    '                   tbl.SEQ,
    '                   ACTIVE = If(tbl.ACTIVE = "Y", True, False)

    '    ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_REASON").Copy)

    '    grdReason.DataSource = ds.Tables("MCUST_REASON")
    '    grdReason.DataBind()
    'End Sub

    Private Sub loadKYCAccount()
        Dim clsDataTable As New clsLINQToDataTable
        Try
            '  Dim convertDate As clsDateFormat = New clsDateFormat
            Dim intANSWERTYPE As Integer = 0

            If Request.QueryString("KYC") = 1 Then
                intANSWERTYPE = 1
            ElseIf Request.QueryString("KYC") = 2 Then
                intANSWERTYPE = 3
            ElseIf Request.QueryString("KYC") = 3 Then
                intANSWERTYPE = 5
            ElseIf Request.QueryString("KYC") = 4 Then
                intANSWERTYPE = 0
            End If

            If ds.Tables.Contains("RKYC") Then
                ds.Tables.Remove("RKYC")
            End If

            Dim qryRKYc = From tblKYC In KYCEntity.RKYC
                         Where tblKYC.CUSTSEQ = CustSeq _
                           And tblKYC.ACCOUNTNO <> ""
                        Select tblKYC.ANSWERTYPE,
                               tblKYC.ACCOUNTNO,
                               tblKYC.APPROVECODE,
                               tblKYC.ACCOUNTNAME,
                               tblKYC.KYCSEQ,
                               tblKYC.WORKERSTATUS,
                               tblKYC.KYCCOMPLETE,
                               tblKYC.APPROVENO,
                               tblKYC.BRANCHCODE,
                               tblKYC.UPDATEBY,
                               tblKYC.F_JOIN_ACCT,
                               tblKYC.ACCT_STATE,
                               FLAG_SELF_BO = If(tblKYC.FLAG_SELF_BO = "Y", True, False),
                               FLAG_OTHP_BO = If(tblKYC.FLAG_OTHP_BO = "Y", True, False),
                               ACTIVE = If(tblKYC.ACTIVE = "Y", True, False)
                      Order By KYCSEQ

            ''
            If Not intANSWERTYPE = 0 Then
                qryRKYc = qryRKYc.Where(Function(fn) fn.ANSWERTYPE = intANSWERTYPE)
            End If

            Dim aa As String = Request.QueryString("SelectGrd")
            ds.Tables.Add(clsDataTable.LINQToDataTable(qryRKYc, "RKYC").Copy)
            grdShowAccount.DataSource = ds.Tables("RKYC")
            grdShowAccount.DataBind()
            Me.lblCount_Show_ACCT.Text = ds.Tables("RKYC").Rows.Count

            If Not aa Is Nothing Then
                grdShowAccount.SelectedIndex = CInt(aa)
                Call grdShowAccount_SelectedIndexChanged(Me, Nothing)
            End If


            If Not acc = "" Then
                For i As Integer = 0 To grdShowAccount.Rows.Count - 1
                    If grdShowAccount.Rows(i).Cells(1).Text = acc Then
                        grdShowAccount.SelectedIndex = i
                        If (grdShowAccount.SelectedIndex = intBeforeItemIndex) Then
                            grdShowAccount.SelectedIndex = -1
                            resetData()

                            'btnAdd.Visible = True
                            'btnAddOld.Visible = False
                        Else
                            clearPanel()
                            Dim strKYCSEQ As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblKYCSeq"), Label).Text
                            Dim strAccName As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblAccountName"), Label).Text
                            hdfKYCSeq.Value = strKYCSEQ
                            TxtAccNo.Text = grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text.Trim

                            If grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(2).Text.Trim = "" Then
                                txtAccName.Text = txtNameTh1.Text & " " & txtNameTh3.Text
                            Else
                                txtAccName.Text = grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(2).Text.Trim
                            End If


                            If Not TxtAccNo.Text.Trim = "" Then

                                If Request.QueryString("KYC") = 1 Then
                                    BindingDataKYCDeposit()
                                ElseIf Request.QueryString("KYC") = 2 Then
                                    BindingDataKYCLoan()
                                ElseIf Request.QueryString("KYC") = 3 Then
                                    BindingDataKYCPN()

                                Else
                                    intANSWERTYPE = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblAnswerType"), Label).Text
                                    ' VisbleKYC()

                                    If intANSWERTYPE = 1 Or intANSWERTYPE = 2 Then
                                        PanelDeposit.Visible = True
                                        PanelLoan.Visible = False
                                        PanelPN.Visible = False
                                        BindingDataKYCDeposit()
                                    ElseIf intANSWERTYPE = 3 Or intANSWERTYPE = 4 Then
                                        PanelDeposit.Visible = False
                                        PanelLoan.Visible = True
                                        PanelPN.Visible = False
                                        BindingDataKYCLoan()
                                    ElseIf intANSWERTYPE = 5 Or intANSWERTYPE = 6 Then
                                        PanelDeposit.Visible = False
                                        PanelLoan.Visible = False
                                        PanelPN.Visible = True
                                        BindingDataKYCPN()
                                    End If



                                End If


                            End If


                        End If
                        Exit For
                    End If
                Next
            End If

        Catch ex As Exception

        End Try


    End Sub

    Private Sub CustCasual()
        Try
            If Request.QueryString("KYC") = 3 Then
                '  lblCustCode.Text = "ลูกค้าตั๋ว"
            Else
                'lblCIF_CBS_NO.Text = "ลูกค้าขาจร"
            End If

            ddlPrefixTH.Enabled = False
            txtNameTh1.Enabled = False
            txtNameTh2.Enabled = False
            txtNameTh3.Enabled = False
            ddlPrefixEN.Enabled = False
            txtNameEn1.Enabled = False
            txtNameEn2.Enabled = False
            txtNameEn3.Enabled = False
            ddlUniqueType.Enabled = False
            txtUniqueID.Enabled = False

            chkExpire_None.Visible = True
            txtEvBy.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            txtEvGen1.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            txtEvExpire1.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            txtBirth1.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            ddlGender.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            ddlStatus.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            ddlNationality.Enabled = False
            ddlOccupation2.Enabled = False
            txtOccOther2.Enabled = False
            ddlOccupation3.Enabled = False
            txtOccOther3.Enabled = False
            ddlBusiness1.Enabled = False
            ddlBusiness2.Enabled = False
            txtBizOther2.Enabled = False
            ddlBusiness3.Enabled = False
            txtBizOther3.Enabled = False
            txtDes1.Enabled = False
            txtDes2.Enabled = False
            txtDes3.Enabled = False

            'txtFormalAddr.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            'txtFormalPhone1.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            ' txtFormalPhone1_1.BackColor = Drawing.Color.FromArgb(255, 204, 204)

            txtIDC_ADDR.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            ddlFormalProvince.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            ddlFormalAmphor.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            ddlFormalTambol.BackColor = Drawing.Color.FromArgb(255, 204, 204)
            txtFORMALZIP.BackColor = Drawing.Color.FromArgb(255, 204, 204)


            ddlIncomeSource1.Enabled = False
            ddlIncomeSource2.Enabled = False
            ddlIncomeSource3.Enabled = False
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub BindingDataKYCDeposit(Optional ByVal strAccount As String = "")
        Try
            Dim intkycSeq As Integer = hdfKYCSeq.Value
            Dim qryTblKYC = From kyc In KYCEntity.RKYC
                          Where kyc.ANSWERTYPE = 1
                          Select kyc

            If Not strAccount = "" Then
                qryTblKYC = qryTblKYC.Where(Function(fn) fn.ACCOUNTNO = strAccount.Trim)
                intCountSearch = qryTblKYC.Count
            Else
                qryTblKYC = qryTblKYC.Where(Function(fn) fn.CUSTSEQ = CustSeq And fn.KYCSEQ = intkycSeq)
            End If

            Dim qryKYC = qryTblKYC.ToList

            If Not qryKYC.Count = 0 Then
                If Not strAccount = "" Then
                    txtAccName.Text = qryKYC(0).ACCOUNTNAME
                End If

                If qryKYC(0).ANSWER101 = 0 Then
                    chkDAcc1.Checked = True
                End If
                If qryKYC(0).ANSWER102 = 0 Then
                    chkDAcc2.Checked = True
                End If
                If qryKYC(0).ANSWER103 = 0 Then
                    chkDAcc3.Checked = True
                End If
                If qryKYC(0).ANSWER104 = 0 Then
                    chkDAcc4.Checked = True
                End If
                If qryKYC(0).ANSWER105 = 0 Then
                    chkDAcc5.Checked = True
                    txtDAccOther.Text = qryKYC(0).ANSWER199
                End If
                If qryKYC(0).ANSWER201 = 0 Then
                    chkDSource1.Checked = True
                End If
                If qryKYC(0).ANSWER202 = 0 Then
                    chkDSource2.Checked = True
                End If
                If qryKYC(0).ANSWER203 = 0 Then
                    chkDSource3.Checked = True
                End If
                If qryKYC(0).ANSWER204 = 0 Then
                    chkDSource4.Checked = True
                End If
                If qryKYC(0).ANSWER205 = 0 Then
                    chkDSource5.Checked = True
                End If
                If qryKYC(0).ANSWER206 = 0 Then
                    chkDSource6.Checked = True
                    txtDSourceOther.Text = qryKYC(0).ANSWER299
                End If

                If Not qryKYC(0).ANSWER301 Is Nothing Then
                    ddlDDeposit.SelectedValue = qryKYC(0).ANSWER301
                End If
                If Not qryKYC(0).ANSWER401 Is Nothing Then
                    ddlDMoney.SelectedValue = qryKYC(0).ANSWER401
                End If

                'If Not qryKYC(0).APPROVECODE Is Nothing Then
                '    btnNext.Visible = True
                '    btnSave.Visible = False
                'End If

                'เพิ่ม KYCSactionC
                If PanelDepositSactionC.Visible = True And strAccount = "" Then
                    If qryKYC(0).ASSET1 = 0 Then
                        chkDAsset1.Checked = True
                    End If
                    If qryKYC(0).ASSET2 = 0 Then
                        chkDAsset2.Checked = True
                    End If
                    If qryKYC(0).ASSET3 = 0 Then
                        chkDAsset3.Checked = True
                    End If
                    If qryKYC(0).ASSET4 = 0 Then
                        chkDAsset4.Checked = True
                    End If
                    If qryKYC(0).ASSET5 = 0 Then
                        chkDAsset5.Checked = True
                    End If
                    If qryKYC(0).ASSET6 = 0 Then
                        chkDAsset6.Checked = True
                        txtDAssetOther.Text = qryKYC(0).ASSETOTHER
                    End If

                    If Not qryKYC(0).APPROVECODE Is Nothing Then
                        ddlDApprove.SelectedValue = qryKYC(0).APPROVECODE
                        txtApprovePassword.Enabled = True
                    End If
                    'txtDApprove.Text = qryKYC(0).APPROVENAME
                    txtDApproveNo.Text = qryKYC(0).APPROVENO

                    Me.lblACCT_STATE.Text = qryKYC(0).ACCT_STATE

                    If Me.lblACCT_STATE.Text = "" Then Me.lblACCT_STATE.Text = "S"

                    Me.lblF_JOIN_ACCT.Text = qryKYC(0).F_JOIN_ACCT
                    If Me.lblF_JOIN_ACCT.Text = "Y" Then
                        Me.chkJoin_Account.Checked = True
                        Me.lblACCT_STATE.Text = "J"
                    Else
                        Me.chkJoin_Account.Checked = False
                        Me.lblACCT_STATE.Text = "S"
                    End If


                    clsDateFormat = New clsDateFormat
                    If qryKYC(0).APPROVEDATE Is Nothing Then
                        txtDApproveDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, Now.Date)
                    ElseIf Not qryKYC(0).APPROVEDATE Is Nothing Then
                        txtDApproveDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryKYC(0).APPROVEDATE)
                        txtApproveDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryKYC(0).APPROVEDATE)
                    End If
                    clsDateFormat = Nothing

                    If Not qryKYC(0).TOTALASSET Is Nothing Then
                        clsMoney = New clsMoney
                        txtDValue.Text = clsMoney.insertComma(qryKYC(0).TOTALASSET)
                        clsMoney = Nothing

                    End If
                End If
            Else

                'If Not Request.QueryString("KYC") = 4 Then
                '    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "message", _
                '                          "alert('" + Resources.resMsgKYC.msgCDD + "');location.href = 'IndividualCDD.aspx?KYC=" & Request.QueryString("KYC") & "&TypeKYC=2&CUSTSEQ=" & CustSeq & "';", True)
                '    Exit Sub
                'End If

            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub BindingDataKYCLoan(Optional ByVal strAccount As String = "")
        Try
            Dim intkycSeq As Integer = hdfKYCSeq.Value
            Dim qryTblKYC = From kyc In KYCEntity.RKYC
                          Where kyc.ANSWERTYPE = 3
                          Select kyc

            If Not strAccount = "" Then
                qryTblKYC = qryTblKYC.Where(Function(fn) fn.ACCOUNTNO = strAccount.Trim)
                intCountSearch = qryTblKYC.Count
            Else
                qryTblKYC = qryTblKYC.Where(Function(fn) fn.CUSTSEQ = CustSeq And fn.KYCSEQ = intkycSeq)

            End If
            Dim qryKYC = qryTblKYC.ToList

            If Not qryKYC.Count = 0 Then
                If Not strAccount = "" Then
                    txtAccName.Text = qryKYC(0).ACCOUNTNAME
                End If

                If qryKYC(0).ANSWER101 = 0 Then
                    chkLAcc1.Checked = True
                End If
                If qryKYC(0).ANSWER102 = 0 Then
                    chkLAcc2.Checked = True
                End If
                If qryKYC(0).ANSWER103 = 0 Then
                    chkLAcc3.Checked = True
                End If
                If qryKYC(0).ANSWER104 = 0 Then
                    chkLAcc4.Checked = True
                End If
                If qryKYC(0).ANSWER105 = 0 Then
                    chkLAcc5.Checked = True
                End If
                If qryKYC(0).ANSWER106 = 0 Then
                    chkLAcc6.Checked = True
                End If
                If qryKYC(0).ANSWER107 = 0 Then
                    chkLAcc7.Checked = True
                End If
                If qryKYC(0).ANSWER108 = 0 Then
                    chkLAcc8.Checked = True
                End If
                If qryKYC(0).ANSWER109 = 0 Then
                    chkLAcc9.Checked = True
                End If
                If qryKYC(0).ANSWER110 = 0 Then
                    chkLAcc10.Checked = True
                    txtLAccOther.Text = qryKYC(0).ANSWER199
                End If

                'If Not qryKYC(0).APPROVECODE Is Nothing Then
                '    btnNext.Visible = True
                '    btnSave.Visible = False
                'End If

                'เพิ่ม KYCSactionC
                If PanelDepositSactionC.Visible = True And strAccount = "" Then


                    If qryKYC(0).ASSET1 = 0 Then
                        chkDAsset1.Checked = True
                    End If
                    If qryKYC(0).ASSET2 = 0 Then
                        chkDAsset2.Checked = True
                    End If
                    If qryKYC(0).ASSET3 = 0 Then
                        chkDAsset3.Checked = True
                    End If
                    If qryKYC(0).ASSET4 = 0 Then
                        chkDAsset4.Checked = True
                    End If
                    If qryKYC(0).ASSET5 = 0 Then
                        chkDAsset5.Checked = True
                    End If
                    If qryKYC(0).ASSET6 = 0 Then
                        chkDAsset6.Checked = True
                        txtDAssetOther.Text = qryKYC(0).ASSETOTHER
                    End If

                    If Not qryKYC(0).APPROVECODE Is Nothing Then
                        ddlDApprove.SelectedValue = qryKYC(0).APPROVECODE
                        txtApprovePassword.Enabled = True
                    End If
                    'txtDApprove.Text = qryKYC(0).APPROVENAME
                    txtDApproveNo.Text = qryKYC(0).APPROVENO

                    clsDateFormat = New clsDateFormat
                    If qryKYC(0).APPROVEDATE Is Nothing Then
                        txtDApproveDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, Now.Date)
                    ElseIf Not qryKYC(0).APPROVEDATE Is Nothing Then
                        txtDApproveDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryKYC(0).APPROVEDATE)
                        txtApproveDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryKYC(0).APPROVEDATE)
                    End If
                    clsDateFormat = Nothing

                    If Not qryKYC(0).TOTALASSET Is Nothing Then
                        clsMoney = New clsMoney
                        txtDValue.Text = clsMoney.insertComma(qryKYC(0).TOTALASSET)
                        clsMoney = Nothing

                    End If
                End If

            Else
                'If Not Request.QueryString("KYC") = 4 Then
                '    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "message", _
                '                          "alert('" + Resources.resMsgKYC.msgCDD + "');location.href = 'IndividualCDD.aspx?KYC=" & Request.QueryString("KYC") & "&TypeKYC=2&CUSTSEQ=" & CustSeq & "';", True)
                '    Exit Sub
                'End If

            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub BindingDataKYCPN(Optional ByVal strAccount As String = "")
        Try

            Dim intkycSeq As Integer = hdfKYCSeq.Value
            Dim qryTblKYC = From kyc In KYCEntity.RKYC
                          Where kyc.ANSWERTYPE = 5
                          Select kyc

            If Not strAccount = "" Then
                qryTblKYC = qryTblKYC.Where(Function(fn) fn.ACCOUNTNO = strAccount.Trim)
                intCountSearch = qryTblKYC.Count
            Else
                qryTblKYC = qryTblKYC.Where(Function(fn) fn.CUSTSEQ = CustSeq And fn.KYCSEQ = intkycSeq)

            End If



            Dim qryKYC = qryTblKYC.ToList

            If Not qryKYC.Count = 0 Then
                If Not strAccount = "" Then
                    txtAccName.Text = qryKYC(0).ACCOUNTNAME
                End If

                If qryKYC(0).ANSWER101 = 0 Then
                    chkPAcc1.Checked = True
                End If
                If qryKYC(0).ANSWER102 = 0 Then
                    chkPAcc2.Checked = True
                End If
                If qryKYC(0).ANSWER103 = 0 Then
                    chkPAcc3.Checked = True
                End If
                If qryKYC(0).ANSWER104 = 0 Then
                    chkPAcc4.Checked = True
                End If
                If qryKYC(0).ANSWER105 = 0 Then
                    chkPAcc5.Checked = True
                    txtPAccOther.Text = qryKYC(0).ANSWER199
                End If
                If qryKYC(0).ANSWER201 = 0 Then
                    chkPSource1.Checked = True
                End If
                If qryKYC(0).ANSWER202 = 0 Then
                    chkPSource2.Checked = True
                End If
                If qryKYC(0).ANSWER203 = 0 Then
                    chkPSource3.Checked = True
                End If
                If qryKYC(0).ANSWER204 = 0 Then
                    chkPSource4.Checked = True
                End If
                If qryKYC(0).ANSWER205 = 0 Then
                    chkPSource5.Checked = True
                End If
                If qryKYC(0).ANSWER206 = 0 Then
                    chkPSource6.Checked = True
                    txtPSourceOther.Text = qryKYC(0).ANSWER299
                End If

                If Not qryKYC(0).ANSWER301 Is Nothing Then
                    ddlPDeposit.SelectedValue = qryKYC(0).ANSWER301
                End If
                If Not qryKYC(0).ANSWER401 Is Nothing Then
                    ddlPMoney.SelectedValue = qryKYC(0).ANSWER401
                End If

                'If Not qryKYC(0).APPROVECODE Is Nothing Then
                '    btnNext.Visible = True
                '    btnSave.Visible = False
                'End If


                'เพิ่ม KYCSactionC
                If PanelDepositSactionC.Visible = True And strAccount = "" Then


                    If qryKYC(0).ASSET1 = 0 Then
                        chkDAsset1.Checked = True
                    End If
                    If qryKYC(0).ASSET2 = 0 Then
                        chkDAsset2.Checked = True
                    End If
                    If qryKYC(0).ASSET3 = 0 Then
                        chkDAsset3.Checked = True
                    End If
                    If qryKYC(0).ASSET4 = 0 Then
                        chkDAsset4.Checked = True
                    End If
                    If qryKYC(0).ASSET5 = 0 Then
                        chkDAsset5.Checked = True
                    End If
                    If qryKYC(0).ASSET6 = 0 Then
                        chkDAsset6.Checked = True
                        txtDAssetOther.Text = qryKYC(0).ASSETOTHER
                    End If

                    If Not qryKYC(0).APPROVECODE Is Nothing Then
                        ddlDApprove.SelectedValue = qryKYC(0).APPROVECODE
                        txtApprovePassword.Enabled = True
                    End If
                    'txtDApprove.Text = qryKYC(0).APPROVENAME
                    txtDApproveNo.Text = qryKYC(0).APPROVENO

                    clsDateFormat = New clsDateFormat
                    If qryKYC(0).APPROVEDATE Is Nothing Then
                        txtDApproveDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, Now.Date)
                    ElseIf Not qryKYC(0).APPROVEDATE Is Nothing Then
                        txtDApproveDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryKYC(0).APPROVEDATE)
                        txtApproveDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryKYC(0).APPROVEDATE)
                    End If
                    clsDateFormat = Nothing

                    If Not qryKYC(0).TOTALASSET Is Nothing Then
                        clsMoney = New clsMoney
                        txtDValue.Text = clsMoney.insertComma(qryKYC(0).TOTALASSET)
                        clsMoney = Nothing

                    End If
                End If
            Else
                'If Not Request.QueryString("KYC") = 4 Then
                '    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "message", _
                '                          "alert('" + Resources.resMsgKYC.msgCDD + "');location.href = 'IndividualCDD.aspx?KYC=" & Request.QueryString("KYC") & "&TypeKYC=2&CUSTSEQ=" & CustSeq & "';", True)
                '    Exit Sub
                'End If

            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#Region "Function Drop Drown"


    Private Sub indexOccupationChanging2()

        If Not ddlOccupation2.SelectedValue = "" Then
            ddlBusiness2.BackColor = Drawing.Color.FromArgb(255, 255, 255)

            If ddlOccupation2.SelectedValue = 98 Then 'กรณีเป็นเจ้าของกิจการ
                txtOccOther2.Visible = False
                lblOther21.Visible = False
                ddlBusiness2.Enabled = True
                ddlBusiness2.BackColor = Drawing.Color.FromArgb(255, 204, 204)

            ElseIf ddlOccupation2.SelectedValue = 99 Then 'ประกอบอาชีพอื่นๆ
                txtOccOther2.Visible = True
                lblOther21.Visible = True
                ddlBusiness2.Enabled = False

                ddlBusiness2.SelectedIndex = 0
                txtBizOther2.Visible = False
                txtBizOther2.Text = ""
                lblOther22.Visible = False
            Else
                txtOccOther2.Visible = False
                txtOccOther2.Text = ""
                lblOther21.Visible = False
                ddlBusiness2.Enabled = False

                ddlBusiness2.SelectedIndex = 0
                txtBizOther2.Visible = False
                txtBizOther2.Text = ""
                lblOther22.Visible = False
            End If
        Else
            txtOccOther2.Visible = False
            txtOccOther2.Text = ""
            lblOther21.Visible = False
            ddlBusiness2.Enabled = False

            ddlBusiness2.SelectedIndex = 0
            txtBizOther2.Visible = False
            txtBizOther2.Text = ""
            lblOther22.Visible = False
        End If

    End Sub

    Private Sub indexBizChanging2()
        If Not ddlBusiness2.SelectedValue = "" Then
            If ddlBusiness2.SelectedValue = 99 Then
                txtBizOther2.Visible = True
                lblOther22.Visible = True
            Else
                txtBizOther2.Visible = False
                txtBizOther2.Text = ""
                lblOther22.Visible = False
            End If
        Else
            txtBizOther2.Visible = False
            txtBizOther2.Text = ""
            lblOther22.Visible = False
        End If

    End Sub

    Private Sub indexOccupationChanging3()

        If Not ddlOccupation3.SelectedValue = "" Then
            If ddlOccupation3.SelectedValue = 98 Then 'กรณีเป็นเจ้าของกิจการ
                txtOccOther3.Visible = False
                lblOther31.Visible = False
                ddlBusiness3.Enabled = True
                ddlBusiness3.BackColor = Drawing.Color.FromArgb(255, 204, 204)

            ElseIf ddlOccupation3.SelectedValue = 99 Then 'ประกอบอาชีพอื่นๆ
                txtOccOther3.Visible = True
                lblOther31.Visible = True
                ddlBusiness3.Enabled = False

                ddlBusiness3.SelectedIndex = 0
                txtBizOther3.Visible = False
                txtBizOther3.Text = ""
                lblOther32.Visible = False
            Else
                txtOccOther3.Visible = False
                txtOccOther3.Text = ""
                lblOther31.Visible = False
                ddlBusiness3.Enabled = False

                ddlBusiness3.SelectedIndex = 0
                txtBizOther3.Visible = False
                txtBizOther3.Text = ""
                lblOther32.Visible = False
            End If
        Else
            txtOccOther3.Visible = False
            txtOccOther3.Text = ""
            lblOther31.Visible = False
            ddlBusiness3.Enabled = False

            ddlBusiness3.SelectedIndex = 0
            txtBizOther3.Visible = False
            txtBizOther3.Text = ""
            lblOther32.Visible = False
        End If


    End Sub

    Private Sub indexBizChanging3()

        If Not ddlBusiness3.SelectedValue = "" Then
            ddlBusiness3.BackColor = Drawing.Color.FromArgb(255, 255, 255)

            If ddlBusiness3.SelectedValue = 99 Then
                txtBizOther3.Visible = True
                lblOther32.Visible = True
            Else
                txtBizOther3.Visible = False
                txtBizOther3.Text = ""
                lblOther32.Visible = False
            End If
        Else
            txtBizOther3.Visible = False
            txtBizOther3.Text = ""
            lblOther32.Visible = False
        End If

    End Sub

#End Region

    Private Function checkBeforeSave() As Boolean
        Try
            Dim result As Boolean = True
            clsDateFormat = New clsDateFormat
            If hdfTranType.Value = 2 Then
                'If txtEvBy.Text = "" Then
                '    result = False
                '    Image8.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.NotEvBy + "\n"
                'Else
                '    Image8.ImageUrl = "~/img/icon/accept.png"
                'End If

                'If txtEvGen1.Text = "" Then
                '    result = False
                '    Image8.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.NotEvGen + "\n"
                'Else
                '    If clsDateFormat.ChkformatDate(txtEvGen1.Text.Trim) = False Then
                '        result = False
                '        Image8.ImageUrl = "~/img/icon/cancel.png"
                '        strMsg = strMsg + Resources.resMsgAlertKYC.NotEvGen + Resources.resMsgAlertKYC.FormatDate + "\n"
                '    Else
                '        If result = True Then
                '            Image8.ImageUrl = "~/img/icon/accept.png"
                '        End If
                '    End If
                'End If

                'If txtEvExpire1.Text = "" And chkExpire_None.Checked = False Then
                '    result = False
                '    Image8.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.NotEvExpire + "\n"
                'ElseIf Not txtEvExpire1.Text = "" And chkExpire_None.Checked = False Then
                '    If clsDateFormat.ChkformatDate(txtEvExpire1.Text.Trim) = False Then
                '        result = False
                '        Image8.ImageUrl = "~/img/icon/cancel.png"
                '        strMsg = strMsg + Resources.resMsgAlertKYC.NotEvExpire + Resources.resMsgAlertKYC.FormatDate + "\n"
                '    Else
                '        If result = True Then
                '            Image8.ImageUrl = "~/img/icon/accept.png"
                '        End If
                '    End If
                'End If

                'If txtBirth1.Text = "" Then
                '    result = False
                '    Image9.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.NotBirth + "\n"
                'Else
                '    If clsDateFormat.ChkformatDate(txtBirth1.Text.Trim) = False Then
                '        result = False
                '        Image9.ImageUrl = "~/img/icon/cancel.png"
                '        strMsg = strMsg + Resources.resMsgAlertKYC.NotBirth + Resources.resMsgAlertKYC.FormatDate + "\n"
                '    Else
                '        Image9.ImageUrl = "~/img/icon/accept.png"
                '    End If
                'End If

                'If ddlGender.SelectedIndex = 0 Then
                '    result = False
                '    Image10.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.NotGender + "\n"
                'Else
                '    Image10.ImageUrl = "~/img/icon/accept.png"
                'End If

                'If ddlStatus.SelectedIndex = 0 Then
                '    result = False
                '    Image10.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.NotMarital + "\n"
                'Else
                '    Image10.ImageUrl = "~/img/icon/accept.png"
                'End If

                'If txtFormalAddress.Text = "" Then
                '    result = False
                '    Image11.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.NotAddressNo + "\n"
                'Else
                '    Image11.ImageUrl = "~/img/icon/accept.png"
                'End If

                'If ddlFormalProvice.SelectedIndex = 0 Then
                '    result = False
                '    Image11.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.NotProvice + "\n"
                'Else
                '    Image11.ImageUrl = "~/img/icon/accept.png"
                'End If

                'If ddlFormalAmphor.SelectedIndex = 0 Then
                '    result = False
                '    Image11.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.NotAmphor + "\n"
                'Else
                '    Image11.ImageUrl = "~/img/icon/accept.png"
                'End If

                'If ddlFormalTambol.SelectedIndex = 0 Then
                '    result = False
                '    Image11.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.NotTambol + "\n"
                'Else
                '    Image11.ImageUrl = "~/img/icon/accept.png"
                'End If

                'If txtFormalPostCode.Text = "" Then
                '    result = False
                '    Image11.ImageUrl = "~/img/icon/cancel.png"
                '    strMsg = strMsg + Resources.resMsgAlertKYC.notPostCode + "\n"
                'Else
                '    Image11.ImageUrl = "~/img/icon/accept.png"
                'End If
            End If

            If ddlCheckName.SelectedIndex = 0 Then
                result = False
                Image1.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotCheckName + "\n"
            Else
                Image1.ImageUrl = "~/img/icon/accept.png"
            End If

            If ddlCheckAddress.SelectedIndex = 0 Then
                result = False
                Image2.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotCheckAddress + "\n"
            Else
                Image2.ImageUrl = "~/img/icon/accept.png"
            End If

            Dim cls As New clsAccount
            If Request.QueryString("KYC") = 1 Then

                If Not cls.chkAccountDisposit(TxtAccNo.Text.Trim) Then
                    strMsg = strMsg + cls.SetMsg + "\n"
                    result = False
                End If

            ElseIf Request.QueryString("KYC") = 2 Then
                If Not cls.chkAccountLoan(TxtAccNo.Text.Trim) Then
                    strMsg = strMsg + cls.SetMsg + "\n"
                    result = False
                End If
            End If
            If Request.QueryString("KYC") = 1 Or Request.QueryString("KYC") = 3 Then
                If txtAccName.Text = "" Then
                    strMsg = strMsg + "กรุณากรอกชื่อบัญชี" + "\n"
                    result = False
                Else
                    If Not IsNumeric(TxtAccNo.Text) Then
                        strMsg = strMsg + "เลขที่บัญชีต้องเป็นตัวเลข" + "\n"
                        result = False
                    End If
                End If
            End If
            'Dim cls As New clsAccount
            'If Not cls.chkAccountDisposit(TxtAccNo.Text.Trim) Then
            '    strMsg = strMsg + cls.SetMsg + "\n"
            'End If
            'If TxtAccNo.Text = "" Then
            '    strMsg = strMsg + "กรุณากรอกเลขที่บัญชี" + "\n"
            'End If



            If Request.QueryString("KYC") = 4 Then
                GoTo deposit
            End If

            If PanelDepositSactionC.Visible = True Then

                If chkDAsset6.Checked = True Then
                    If txtDAssetOther.Text = "" Then
                        result = False
                        ImgSactionC5.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + Resources.resMsgAlertKYC.NotOther + "\n"
                    Else
                        ImgSactionC5.ImageUrl = "~/img/icon/accept.png"
                    End If
                End If

            End If




            If Request.QueryString("KYC") = 1 Then
deposit:


                If chkDAcc5.Checked = True And txtDAccOther.Text.Trim = "" Then
                    result = False
                    Image3.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotOther + "\n"
                Else
                    Image3.ImageUrl = "~/img/icon/accept.png"
                End If
                If chkDSource6.Checked = True And txtDSourceOther.Text.Trim = "" Then
                    result = False
                    Image4.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotOther + "\n"
                Else
                    Image4.ImageUrl = "~/img/icon/accept.png"
                End If

                If Request.QueryString("KYC") = 4 Then
                    GoTo loan
                End If

            ElseIf Request.QueryString("KYC") = 2 Then
loan:

                If chkLAcc10.Checked = True And txtLAccOther.Text.Trim = "" Then
                    result = False
                    Image5.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotOther + "\n"
                Else
                    Image5.ImageUrl = "~/img/icon/accept.png"
                End If

                If Request.QueryString("KYC") = 4 Then
                    GoTo pn
                End If
            ElseIf Request.QueryString("KYC") = 3 Then
pn:
                If chkPAcc5.Checked = True And txtPAccOther.Text.Trim = "" Then
                    result = False
                    Image6.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotOther + "\n"
                Else
                    Image6.ImageUrl = "~/img/icon/accept.png"
                End If
                If chkPSource6.Checked = True And txtPSourceOther.Text.Trim = "" Then
                    result = False
                    Image7.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotOther + "\n"
                Else
                    Image7.ImageUrl = "~/img/icon/accept.png"
                End If


            End If

            If result = False Then
                statusValidation()
            End If
            clsDateFormat = Nothing
            Return result
        Catch ex As Exception
            Throw ex
        End Try
    End Function


    Private Function checkNpaSave() As Boolean
        Try
            Dim result As Boolean = True
            clsDateFormat = New clsDateFormat
            If hdfTranType.Value = 2 Then
                If txtEvBy.Text = "" Then
                    result = False
                    Image8.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotEvBy + "\n"
                Else
                    Image8.ImageUrl = "~/img/icon/accept.png"
                End If
                If txtEvGen1.Text = "" Then
                    result = False
                    Image8.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotEvGen + "\n"
                Else
                    If clsDateFormat.ChkformatDate(txtEvGen1.Text.Trim) = False Then
                        result = False
                        Image8.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + Resources.resMsgAlertKYC.NotEvGen + Resources.resMsgAlertKYC.FormatDate + "\n"
                    Else
                        If result = True Then
                            Image8.ImageUrl = "~/img/icon/accept.png"
                        End If
                    End If
                End If
                If txtEvExpire1.Text = "" And chkExpire_None.Checked = False Then
                    result = False
                    Image8.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotEvExpire + "\n"
                ElseIf Not txtEvExpire1.Text = "" And chkExpire_None.Checked = False Then
                    If clsDateFormat.ChkformatDate(txtEvExpire1.Text.Trim) = False Then
                        result = False
                        Image8.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + Resources.resMsgAlertKYC.NotEvExpire + Resources.resMsgAlertKYC.FormatDate + "\n"
                    Else
                        If result = True Then
                            Image8.ImageUrl = "~/img/icon/accept.png"
                        End If
                    End If
                End If
                If txtBirth1.Text = "" Then
                    result = False
                    Image9.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotBirth + "\n"
                Else
                    If clsDateFormat.ChkformatDate(txtBirth1.Text.Trim) = False Then
                        result = False
                        Image9.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + Resources.resMsgAlertKYC.NotBirth + Resources.resMsgAlertKYC.FormatDate + "\n"
                    Else
                        Image9.ImageUrl = "~/img/icon/accept.png"
                    End If
                End If
                If ddlGender.SelectedIndex = 0 Then
                    result = False
                    Image10.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotGender + "\n"
                Else
                    Image10.ImageUrl = "~/img/icon/accept.png"
                End If
                If ddlStatus.SelectedIndex = 0 Then
                    result = False
                    Image10.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotMarital + "\n"
                Else
                    Image10.ImageUrl = "~/img/icon/accept.png"
                End If

                If txtIDC_ADDR.Text = "" Then
                    result = False
                    Image11.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotAddressNo + "\n"
                Else
                    Image11.ImageUrl = "~/img/icon/accept.png"
                End If

                If ddlFormalProvince.SelectedIndex = 0 Then
                    result = False
                    Image11.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotProvice + "\n"
                Else
                    Image11.ImageUrl = "~/img/icon/accept.png"
                End If

                If ddlFormalAmphor.SelectedIndex = 0 Then
                    result = False
                    Image11.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotAmphor + "\n"
                Else
                    Image11.ImageUrl = "~/img/icon/accept.png"
                End If

                If ddlFormalTambol.SelectedIndex = 0 Then
                    result = False
                    Image11.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotTambol + "\n"
                Else
                    Image11.ImageUrl = "~/img/icon/accept.png"
                End If

                If txtFORMALZIP.Text = "" Then
                    result = False
                    Image11.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.notPostCode + "\n"
                Else
                    Image11.ImageUrl = "~/img/icon/accept.png"
                End If
            End If

            If ddlCheckName.SelectedIndex = 0 Then
                result = False
                Image1.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotCheckName + "\n"
            Else
                Image1.ImageUrl = "~/img/icon/accept.png"
            End If

            If ddlCheckAddress.SelectedIndex = 0 Then
                result = False
                Image2.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotCheckAddress + "\n"
            Else
                Image2.ImageUrl = "~/img/icon/accept.png"
            End If




            If result = False Then
                statusValidation()
            End If
            clsDateFormat = Nothing
            Return result
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Private Function checkApprove() As Boolean
        Try
            Dim result As Boolean = True

            If ddlDApprove.SelectedIndex = 0 Then
                result = False
                ImgSactionC3.ImageUrl = "~/img/icon/cancel.png"
                ImgSactionC3.Visible = True
                strMsg = strMsg + Resources.resMsgAlertKYC.NotStatusApprove + "\n"
            ElseIf ddlDApprove.SelectedValue = 2 Or ddlDApprove.SelectedValue = 3 Then
                ImgSactionC4.ImageUrl = "~/img/icon/accept.png"
                If txtDApproveNo.Text.Trim = "" Then
                    result = False
                    ImgSactionC4.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotApproveNo + "\n"
                Else
                    Dim clsCheckApprove As clsCheckApprove = New clsCheckApprove
                    Dim strApp As String = clsCheckApprove.checkRightApprove(txtDApproveNo.Text, clsSessionMenuRight.getUserName, clsSessionMenuRight.getRoleGroup, clsSessionMenuRight.getBranchCode, clsSessionMenuRight.getZoneCode, clsSessionMenuRight.getDeptCode, txtApprovePassword.Text)

                    If strApp = "" Then
                        ImgSactionC4.ImageUrl = "~/img/icon/accept.png"
                    Else
                        result = False
                        ImgSactionC4.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + strApp + "\n"
                    End If
                End If
                If txtDApproveDate.Text = "" Then
                    result = False
                    ImgSactionC5.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotApproveDate + "\n"
                Else
                    ImgSactionC5.ImageUrl = "~/img/icon/accept.png"
                End If

                ImgSactionC3.Visible = True
                ImgSactionC4.Visible = True
                ImgSactionC5.Visible = True

            End If

            Return result
        Catch ex As Exception
            Throw ex
        End Try
    End Function


    Sub statusValidation()

        Image1.Visible = True
        Image2.Visible = True
        Image3.Visible = True
        Image4.Visible = True
        Image5.Visible = True
        Image6.Visible = True
        Image7.Visible = True

        If hdfTranType.Value = 2 Then
            Image8.Visible = True
            Image9.Visible = True
            Image10.Visible = True
            Image11.Visible = True
        End If

        If PanelDepositSactionC.Visible = True Then
            ImgSactionC5.Visible = True
        End If

    End Sub

    Private Sub saveData()
        KYCEntity = New KYCEntities
        KYCEntity.Connection.Open()
        Using transaction As System.Data.Common.DbTransaction = KYCEntity.Connection.BeginTransaction()
            Try
                saveCustomer()

                ''''Prachak '''''''''''''''''''''''''''
                Me.Save_to_MCUST_BO_Deposit(CustSeq, Me.TxtAccNo.Text)

                '''''Deposit'''''''''''''''''''''''''''
                Me.Save_to_MCUST_OBJ_Deposit(CustSeq, Me.TxtAccNo.Text)
                Me.Save_to_MCUST_SOURCE_DEPOSIT(CustSeq, Me.TxtAccNo.Text)

                '' '''''Loan ''''''''''''''''''''''''''''''
                Me.Save_to_MCUST_OBJ_Loan(CustSeq, Me.TxtAccNo.Text)

                '' '''''Promisary Note ''''''''''''''''''''''''''''''
                Me.Save_to_MCUST_OBJ_PN(CustSeq, Me.TxtAccNo.Text)
                Me.Save_to_MCUST_SOURCE_PN(CustSeq, Me.TxtAccNo.Text)

                If Me.chkJoin_Account.Checked = True Then
                    If Me.lblHEAD_CUSTSEQ.Text <> "" Then
                        Me.UpdateRKYC_HEAD_ACCT(Me.lblHEAD_CUSTSEQ.Text, Me.TxtAccNo.Text)
                    End If
                End If


                ''''Prachak '''''''''''''''''''
                If Request.QueryString("KYC") = 1 Then
                    If Me.lblKYCSEQ.Text = "-1" Then
                        Me.saveNewKYCDeposit()
                    Else
                        Me.saveUpdateKYCDeposit()
                    End If

                ElseIf Request.QueryString("KYC") = 2 Then
                    If Me.lblKYCSEQ.Text = "-1" Then
                        saveNewKYCLoan()
                    Else
                        saveUpdateKYCLoan()
                    End If

                ElseIf Request.QueryString("KYC") = 3 Then
                    If Me.lblKYCSEQ.Text = "-1" Then
                        saveNewKYCPN()
                    Else
                        saveUpdateKYCPN()
                    End If
                End If

                '''''''''
                Me.grdShowAccount.SelectedIndex = -1
                Me.btnSave.Visible = False
                Me.chkJoin_Account.Checked = False


                ' '' ''If (ds.Tables("rkyc").Rows.Count > 0) Then
                ' '' ''    If Request.QueryString("KYC") = 4 Then
                ' '' ''        If statusTran(1) = 0 Then 'New
                ' '' ''            saveNewKYCDeposit()
                ' '' ''        Else
                ' '' ''            saveUpdateKYCDeposit()
                ' '' ''        End If
                ' '' ''        If statusTran(2) = 0 Then 'New
                ' '' ''            saveNewKYCLoan()
                ' '' ''        Else
                ' '' ''            saveUpdateKYCLoan()
                ' '' ''        End If
                ' '' ''        If statusTran(3) = 0 Then 'New
                ' '' ''            saveNewKYCPN()
                ' '' ''        Else
                ' '' ''            saveUpdateKYCPN()
                ' '' ''        End If
                ' '' ''    Else
                ' '' ''        If statusTran(CInt(Request.QueryString("KYC"))) = 0 Then 'New
                ' '' ''            If Request.QueryString("KYC") = 1 Then
                ' '' ''                saveNewKYCDeposit()
                ' '' ''            ElseIf Request.QueryString("KYC") = 2 Then
                ' '' ''                saveNewKYCLoan()
                ' '' ''            ElseIf Request.QueryString("KYC") = 3 Then
                ' '' ''                saveNewKYCPN()
                ' '' ''            End If

                ' '' ''        Else 'Edit
                ' '' ''            If Request.QueryString("KYC") = 1 Then
                ' '' ''                saveUpdateKYCDeposit()
                ' '' ''            ElseIf Request.QueryString("KYC") = 2 Then
                ' '' ''                saveUpdateKYCLoan()
                ' '' ''            ElseIf Request.QueryString("KYC") = 3 Then
                ' '' ''                saveUpdateKYCPN()
                ' '' ''            End If

                ' '' ''        End If
                ' '' ''    End If

                ' '' ''End If

                transaction.Commit()
            Catch ex As Exception
                transaction.Rollback()
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('Error : " & ex.ToString & " Error message : " & ex.Message & "')", True)
            End Try
        End Using

        KYCEntity.SaveChanges()
        KYCEntity = Nothing
    End Sub

    Private Sub saveNPA()
        KYCEntity = New KYCEntities
        KYCEntity.Connection.Open()
        Using transaction As System.Data.Common.DbTransaction = KYCEntity.Connection.BeginTransaction()
            Try
                saveCustomer()
                transaction.Commit()
            Catch ex As Exception
                transaction.Rollback()
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('Error : " & ex.ToString & " Error message : " & ex.Message & "')", True)
            End Try
        End Using

        KYCEntity.SaveChanges()
        KYCEntity = Nothing
    End Sub



    Private Function statusTran(ByVal KYC As Integer) As Integer
        Try
            'Dim KYC As Integer = CInt(Request.QueryString("KYC"))
            If KYC = 1 Then
                KYC = 1
            ElseIf KYC = 2 Then
                KYC = 3
            ElseIf KYC = 3 Then
                KYC = 5
            End If

            Dim tran As Integer
            Dim qryK = (From k In KYCEntity.RKYC
                         Where k.CUSTSEQ = CustSeq And k.ANSWERTYPE = KYC
                         Select k.CUSTSEQ).ToList

            Dim i As Integer = qryK.Count
            If i = 0 Then
                tran = 0 'New
            Else
                tran = 1 'Edit
            End If

            Return tran
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Private Sub saveCustomer()

        Try

            Dim strTempProvince As String = ""
            Dim strTempTambol As String = ""
            Dim strTempAmphor As String = ""

            Dim updateCust = (From Cust In KYCEntity.MCUSTOMER
                             Where Cust.CUSTSEQ = CustSeq
                            Select Cust).First()

            updateCust.CHECKNAME = ddlCheckName.SelectedValue
            updateCust.CHECKADDRESS = ddlCheckAddress.SelectedValue

            If hdfTranType.Value = 2 Then
                Dim clsFormatDate As clsDateFormat = New clsDateFormat

                updateCust.EVBY = txtEvBy.Text
                updateCust.EVGEN = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtEvGen1.Text)
                updateCust.EVEXPIRE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtEvExpire1.Text)

                '''''''formal Address  line 26 ''''''''''''''''''''''''''''''
                updateCust.FORMALADDR = txtFORMALADDR.Text.Trim
                updateCust.FORMALMOO = txtFORMALMOO.Text.Trim
                updateCust.FORMALSTREET = txtFORMALSTREETDESC.Text.Trim
                updateCust.FORMALSOIDESC = txtFORMALSOIDESC.Text.Trim
                updateCust.FORMALBUILDING = txtFormalBuilding.Text.Trim

                'If ddlFormalProvince.SelectedValue <> 0 Then
                '    updateCust.FORMALPROVINCE = ddlFormalProvince.SelectedValue
                'End If

                'If ddlFormalAmphor.SelectedValue <> 0 Then
                '    updateCust.FORMALAMPHOR = ddlFormalAmphor.SelectedValue
                'End If

                'If ddlFormalTambol.SelectedValue <> 0 Then
                '    updateCust.FORMALTAMBOL = ddlFormalTambol.SelectedValue
                'End If

                updateCust.FORMALPHONE1 = txtFORMALPHONE1.Text.Trim
                updateCust.FORMALPHONE2 = txtFORMALPHONE2.Text.Trim
                updateCust.FORMALPHONE3 = txtFORMALPHONE3.Text.Trim
                updateCust.FORMALFAX = txtFORMALFAX.Text.Trim
                updateCust.FORMALZIP = txtFORMALZIP.Text.Trim

                '''''''IDC Address  line 27 ''''''''''''''''''''''''''''''
                updateCust.IDC_ADDR = txtIDC_ADDR.Text.Trim
                updateCust.IDC_MOO = txtIDC_MOO.Text.Trim
                updateCust.IDC_STREET = txtIDC_STREETDESC.Text.Trim
                updateCust.IDC_SOIDESC = txtIDC_SOIDESC.Text.Trim
                'If ddlIDC_PROVINCE.SelectedIndex <> 0 Then
                '    updateCust.IDC_PROVINCE = ddlIDC_PROVINCE.SelectedValue
                'End If
                'If ddlIDC_AMPHOR.SelectedIndex <> 0 Then
                '    updateCust.IDC_AMPHOR = ddlIDC_AMPHOR.SelectedValue
                'End If
                'If ddlIDC_TAMBOL.SelectedIndex <> 0 Then
                '    updateCust.IDC_TAMBOL = ddlIDC_TAMBOL.SelectedValue
                'End If

                updateCust.IDC_PHONE1 = txtIDC_PHONE1.Text.Trim
                updateCust.IDC_PHONE2 = txtIDC_PHONE2.Text.Trim
                updateCust.IDC_PHONE3 = txtIDC_PHONE3.Text.Trim
                updateCust.IDC_FAX = txtIDC_FAX.Text.Trim
                updateCust.IDC_ZIP = txtIDC_ZIP.Text.Trim

                '''''''TBR Address  line 28 ''''''''''''''''''''''''''''''
                updateCust.TBR_ADDR = txtTBR_ADDR.Text.Trim
                updateCust.TBR_MOO = txtTBR_MOO.Text.Trim
                updateCust.TBR_STREET = txtTBR_STREETDESC.Text.Trim
                updateCust.TBR_SOIDESC = txtTBR_SOIDESC.Text.Trim

                'If ddlTBR_Province.SelectedIndex <> 0 Then
                '    updateCust.TBR_PROVINCE = ddlTBR_Province.SelectedValue
                'End If
                'If ddlTBR_Amphor.SelectedIndex <> 0 Then
                '    updateCust.TBR_AMPHOR = ddlTBR_Amphor.SelectedValue
                'End If
                'If ddlTBR_Tambol.SelectedIndex <> 0 Then
                '    updateCust.TBR_TAMBOL = ddlTBR_Tambol.SelectedValue
                'End If
                updateCust.TBR_PHONE1 = txtTBR_PHONE1.Text.Trim
                updateCust.TBR_PHONE2 = txtTBR_PHONE2.Text.Trim
                updateCust.TBR_PHONE3 = txtTBR_PHONE3.Text.Trim
                updateCust.TBR_FAX = txtTBR_FAX.Text.Trim
                updateCust.TBR_ZIP = txtTBR_ZIP.Text.Trim

                ''''Contact Address line 29 ''''''''''''''''''''''''
                updateCust.CONTACTADDR = Me.txtCONTACTADDR.Text
                updateCust.CONTACTMOO = Me.txtCONTACTMOO.Text.Trim
                updateCust.CONTACTSTREETDESC = Me.txtTBR_STREETDESC.Text.Trim
                updateCust.CONTACTSOIDESC = Me.txtCONTACTSOIDESC.Text.Trim
                'updateCust.CONTACTPROVINCE = Me.ddlCONTACTPROVINCE.SelectedValue
                'updateCust.CONTACTAMPHOR = Me.ddlCONTACTAMPHOR.SelectedValue
                'updateCust.CONTACTTAMBOL = Me.ddlCONTACTTAMBOL.SelectedValue
                updateCust.CONTACTPHONE1 = Me.txtCONTACTPHONE1.Text.Trim
                updateCust.CONTACTPHONE2 = Me.txtCONTACTPHONE2.Text.Trim
                updateCust.CONTACTPHONE3 = Me.txtCONTACTPHONE3.Text.Trim
                updateCust.CONTACTFAX = Me.txtCONTACTFAX.Text.Trim
                updateCust.CONTACTZIP = Me.txtCONTACTZIP.Text.Trim

                ''''KYC Address line 30 ''''''''''''''''''''''''
                '''' อยู่ในปุ่ม -บันทึก- บรรทัดที่ 30 แยกต่างหาก
                ''''''''''''''''''''''''''''''''''''''''''''''''

                If PanelDepositSactionC.Visible = True Then
                    updateCust.APPROVECODE = 0
                End If



                clsFormatDate = Nothing
            Else

            End If

            If strCdd = "1" Then
                If Request.QueryString("KYC") = 1 Then
                    updateCust.DEPUPDATE = "D"

                    Dim strKYCSEQ As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblKYCSeq"), Label).Text


                    Dim intCountComplete As Integer = 0
                    For i As Integer = 0 To ds.Tables("rkyc").Rows.Count - 1
                        If Not strKYCSEQ = ds.Tables("rkyc").Rows(i).Item("KYCSEQ").ToString Then
                            If ds.Tables("rkyc").Rows(i).Item("KYCCOMPLETE").ToString.Trim = "N" Then
                                intCountComplete += 1
                            End If
                        End If
                    Next
                    If intCountComplete = 0 Then
                        If chkDataKYC(1) Then
                            updateCust.DEPD = "Y"
                        Else
                            updateCust.DEPD = "N"
                        End If

                    Else
                        updateCust.DEPD = "N"
                    End If

                    '  updateCust.DEPD = "Y"
                ElseIf Request.QueryString("KYC") = 2 Then
                    updateCust.DEPUPDATE = "L"
                    Dim intCountComplete As Integer = 0
                    If (grdShowAccount.SelectedIndex > -1) Then
                        Dim strKYCSEQ As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblKYCSeq"), Label).Text

                        For i As Integer = 0 To ds.Tables("rkyc").Rows.Count - 1
                            If Not strKYCSEQ = ds.Tables("rkyc").Rows(i).Item("KYCSEQ").ToString Then
                                If ds.Tables("rkyc").Rows(i).Item("KYCCOMPLETE").ToString.Trim = "N" Then
                                    intCountComplete += 1
                                End If
                            End If
                        Next
                    End If

                    If intCountComplete = 0 Then
                        If chkDataKYC(2) Then
                            updateCust.DEPL = "Y"
                        Else
                            If (grdShowAccount.SelectedIndex > -1) Then
                                updateCust.DEPL = "N"
                            Else
                                updateCust.DEPL = "Y"
                            End If

                        End If
                    Else
                        updateCust.DEPL = "N"
                    End If
                    ' updateCust.DEPL = "Y"
                ElseIf Request.QueryString("KYC") = 3 Then
                    updateCust.DEPUPDATE = "P"
                    Dim strKYCSEQ As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblKYCSeq"), Label).Text


                    Dim intCountComplete As Integer = 0
                    For i As Integer = 0 To ds.Tables("rkyc").Rows.Count - 1
                        If Not strKYCSEQ = ds.Tables("rkyc").Rows(i).Item("KYCSEQ").ToString Then
                            If ds.Tables("rkyc").Rows(i).Item("KYCCOMPLETE").ToString.Trim = "N" Then
                                intCountComplete += 1
                            End If
                        End If
                    Next
                    If intCountComplete = 0 Then
                        If chkDataKYC(3) Then
                            updateCust.DEPP = "Y"
                        Else
                            updateCust.DEPP = "N"
                        End If

                    Else
                        updateCust.DEPP = "N"
                    End If
                    ' updateCust.DEPP = "Y"
                ElseIf Request.QueryString("KYC") = 5 Then
                    updateCust.DEPUPDATE = "N"
                    updateCust.DEPN = "Y"

                    ' updateCust.DEPN = "Y"
                End If
            Else


                'If ddlDApprove.SelectedValue = 1 Then
                '    ' newKYC.KYCCOMPLETE = "N"
                'Else
                '    ' newKYC.KYCCOMPLETE = "Y" 'ถือว่าทำ KYC สมบูรณ์แล้ว
                'End If



                If Request.QueryString("KYC") = 1 Then
                    updateCust.DEPUPDATE = "D"
                    'If ddlDApprove.SelectedValue = 1 Then
                    '    updateCust.DEPD = "N"

                    'Else
                    Dim strKYCSEQ As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblKYCSeq"), Label).Text


                    Dim intCountComplete As Integer = 0
                    For i As Integer = 0 To ds.Tables("rkyc").Rows.Count - 1
                        If Not strKYCSEQ = ds.Tables("rkyc").Rows(i).Item("KYCSEQ").ToString Then
                            If ds.Tables("rkyc").Rows(i).Item("KYCCOMPLETE").ToString.Trim = "N" Then
                                intCountComplete += 1
                            End If
                        End If
                    Next
                    If intCountComplete = 0 Then
                        updateCust.DEPD = "Y"
                    Else
                        updateCust.DEPD = "N"
                    End If
                    'End If

                ElseIf Request.QueryString("KYC") = 2 Then
                    updateCust.DEPUPDATE = "L"
                    'If ddlDApprove.SelectedValue = 1 Then
                    '    updateCust.DEPL = "N"
                    'Else
                    Dim intCountComplete As Integer = 0
                    For i As Integer = 0 To ds.Tables("rkyc").Rows.Count - 1
                        If ds.Tables("rkyc").Rows(i).Item("KYCCOMPLETE").ToString.Trim = "N" Then
                            intCountComplete += 1

                        End If
                    Next
                    If intCountComplete = 0 Then
                        updateCust.DEPL = "Y"
                    Else
                        updateCust.DEPL = "N"
                    End If
                    'End If

                ElseIf Request.QueryString("KYC") = 3 Then
                    updateCust.DEPUPDATE = "P"
                    'If ddlDApprove.SelectedValue = 1 Then
                    '    updateCust.DEPP = "N"
                    'Else
                    Dim intCountComplete As Integer = 0
                    For i As Integer = 0 To ds.Tables("rkyc").Rows.Count - 1
                        If ds.Tables("rkyc").Rows(i).Item("KYCCOMPLETE").ToString.Trim = "N" Then
                            intCountComplete += 1
                        End If
                    Next
                    If intCountComplete = 0 Then
                        updateCust.DEPP = "Y"
                    Else
                        updateCust.DEPP = "N"
                    End If
                    'End If
                ElseIf Request.QueryString("KYC") = 5 Then
                    updateCust.DEPUPDATE = "N"
                    updateCust.DEPN = "Y"

                    ' updateCust.DEPN = "Y"
                End If
            End If
            If PanelDepositSactionC.Visible = True Then
                ' updateCust.APPROVECODE = ddlDApprove.SelectedValue
                updateCust.APPROVECODE = 0
            End If
            'updateCust.UPDATEBY = clsSessionMenuRight.getUserName
            'updateCust.UPDATEDATE = Now.ToShortDateString
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub saveUpdateKYCDeposit()
        Dim lvsCustType As Integer = Session("KYC")
        Try
            Dim intKycSeq As Integer = hdfKYCSeq.Value
            Dim updateKYC = (From k In KYCEntity.RKYC
                           Where k.CUSTSEQ = CustSeq And k.KYCSEQ = intKycSeq And k.ANSWERTYPE = 1
                           Select k).First()

            'updateKYC.CHECKNAME = ddlCheckName.SelectedValue
            'updateKYC.CHECKADDRESS = ddlCheckAddress.SelectedValue
            updateKYC.ACCOUNTNO = TxtAccNo.Text.Trim
            updateKYC.ACCOUNTNAME = txtAccName.Text.Trim
            updateKYC.WORKERSTATUS = "0"

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''Prachak '''''''''''''''''''''''''''''''''''''''''''''
            updateKYC.ACCT_STATE = Me.lblACCT_STATE.Text
            '''''''Self BO'''''''''''''''
            If chkBO_SELF.Checked = True Then
                updateKYC.FLAG_SELF_BO = "Y"
            Else
                updateKYC.FLAG_SELF_BO = "N"
            End If
            ''''BO Other ''''''''''''''''''
            If chkBO_OTH.Checked = True Then
                updateKYC.FLAG_OTHP_BO = "Y"
            Else
                updateKYC.FLAG_OTHP_BO = "N"
            End If
            ''''Active'''''''''''''''''''''''
            updateKYC.ACTIVE = Me.lblACTIVE.Text
            updateKYC.CUSTTYPE = lvsCustType
            updateKYC.F_JOIN_ACCT = Me.lblF_JOIN_ACCT.Text
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            'Dim intAns1 As Integer = 0
            'Dim intAns2 As Integer = 0


            'If chkDAcc1.Checked = True Then
            '    updateKYC.ANSWER101 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER101 = 1
            'End If
            'If chkDAcc2.Checked = True Then
            '    updateKYC.ANSWER102 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER102 = 1
            'End If
            'If chkDAcc3.Checked = True Then
            '    updateKYC.ANSWER103 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER103 = 1
            'End If
            'If chkDAcc4.Checked = True Then
            '    updateKYC.ANSWER104 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER104 = 1
            'End If
            'If chkDAcc5.Checked = True Then
            '    updateKYC.ANSWER105 = 0
            '    intAns1 += 1
            '    updateKYC.ANSWER199 = txtDAccOther.Text.Trim
            'Else
            '    updateKYC.ANSWER105 = 1
            'End If

            'If chkDSource1.Checked = True Then
            '    updateKYC.ANSWER201 = 0
            '    intAns2 += 1
            'Else
            '    updateKYC.ANSWER201 = 1
            'End If
            'If chkDSource2.Checked = True Then
            '    updateKYC.ANSWER202 = 0
            '    intAns2 += 1
            'Else
            '    updateKYC.ANSWER202 = 1
            'End If
            'If chkDSource3.Checked = True Then
            '    updateKYC.ANSWER203 = 0
            '    intAns2 += 1
            'Else
            '    updateKYC.ANSWER203 = 1
            'End If
            'If chkDSource4.Checked = True Then
            '    updateKYC.ANSWER204 = 0
            '    intAns2 += 1
            'Else
            '    updateKYC.ANSWER204 = 1
            'End If
            'If chkDSource5.Checked = True Then
            '    updateKYC.ANSWER205 = 0
            '    intAns2 += 1
            'Else
            '    updateKYC.ANSWER205 = 1
            'End If
            'If chkDSource6.Checked = True Then
            '    updateKYC.ANSWER206 = 0
            '    intAns2 += 1
            '    updateKYC.ANSWER299 = txtDSourceOther.Text.Trim
            'Else
            '    updateKYC.ANSWER206 = 1
            'End If

            updateKYC.ANSWER301 = ddlDDeposit.SelectedValue
            updateKYC.ANSWER401 = ddlDMoney.SelectedValue


            If PanelDepositSactionC.Visible = True Then

                'If chkDAsset1.Checked = True Then
                '    updateKYC.ASSET1 = 0
                'Else
                '    updateKYC.ASSET1 = 1
                'End If
                'If chkDAsset2.Checked = True Then
                '    updateKYC.ASSET2 = 0
                'Else
                '    updateKYC.ASSET2 = 1
                'End If
                'If chkDAsset3.Checked = True Then
                '    updateKYC.ASSET3 = 0
                'Else
                '    updateKYC.ASSET3 = 1
                'End If
                'If chkDAsset4.Checked = True Then
                '    updateKYC.ASSET4 = 0
                'Else
                '    updateKYC.ASSET4 = 1
                'End If
                'If chkDAsset5.Checked = True Then
                '    updateKYC.ASSET5 = 0
                'Else
                '    updateKYC.ASSET5 = 1
                'End If
                'If chkDAsset6.Checked = True Then
                '    updateKYC.ASSET6 = 0
                '    updateKYC.ASSETOTHER = txtDAssetOther.Text
                'Else
                '    updateKYC.ASSET6 = 1
                'End If

                'If txtDValue.Text = "" Then
                '    updateKYC.TOTALASSET = Nothing
                'Else
                '    clsMoney = New clsMoney
                '    updateKYC.TOTALASSET = clsMoney.deleteComma(txtDValue.Text.Trim)
                '    clsMoney = Nothing
                'End If


                updateKYC.APPROVECODE = ddlDApprove.SelectedValue
                updateKYC.APPROVENAME = txtDApproveNo.Text.Trim
                updateKYC.APPROVENO = txtDApproveNo.Text.Trim
                If txtDApproveDate.Text = "" Then
                    updateKYC.APPROVEDATE = Nothing
                Else
                    Dim clsFormatDate As clsDateFormat = New clsDateFormat
                    updateKYC.APPROVEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDApproveDate.Text)
                    clsFormatDate = Nothing
                End If


                'If ddlDApprove.SelectedValue = 1 Then
                '    updateKYC.KYCCOMPLETE = "N"
                'Else
                'If intAns1 = 0 Or intAns2 = 0 Or ddlDDeposit.SelectedIndex = 0 Or ddlDMoney.SelectedIndex = 0 Then
                '    updateKYC.KYCCOMPLETE = "N"
                'Else
                '    updateKYC.KYCCOMPLETE = "Y" 'ถือว่าทำ KYC สมบูรณ์แล้ว
                'End If

                'End If
            Else
                'If strCdd = "1" Then
                'If intAns1 = 0 Or intAns2 = 0 Or ddlDDeposit.SelectedIndex = 0 Or ddlDMoney.SelectedIndex = 0 Then
                '    updateKYC.KYCCOMPLETE = "N"
                'Else
                '    updateKYC.KYCCOMPLETE = "Y"
                'End If

                'Else
                '    updateKYC.KYCCOMPLETE = ""
                'End If

            End If


            If Request.QueryString("KYC") = 1 Then
                updateKYC.DEPUPDATE = "D"
            ElseIf Request.QueryString("KYC") = 2 Then
                updateKYC.DEPUPDATE = "L"
            ElseIf Request.QueryString("KYC") = 3 Then
                updateKYC.DEPUPDATE = "P"
            End If

            updateKYC.BRANCHCODE = clsSessionMenuRight.getBranchCode
            updateKYC.ZONECODE = clsSessionMenuRight.getZoneCode
            updateKYC.DEPTCODE = clsSessionMenuRight.getDeptCode
            updateKYC.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight


            updateKYC.UPDATEBY = clsSessionMenuRight.getUserName
            updateKYC.UPDATEDATE = Now.ToShortDateString
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub saveNewKYCDeposit()
        Dim lvsCustType As Integer = Session("KYC")
        Try
            If ds.Tables.Contains("GENKYC") Then
                ds.Tables.Remove("GENKYC")
            End If

            Dim sql As String = "select " & System.Configuration.ConfigurationSettings.AppSettings("SequentRKYC_S") & " from dual"
            ''''Dim sql As String = "select " & System.Configuration.ConfigurationManager.AppSettings("SequentRKYC_S") & " from dual"
            ds.Tables.Add(clsDatabase.QueryDataSet(sql, "GENKYC").Tables("GENKYC").Copy)
            Dim key As Integer = ds.Tables("GENKYC").Rows(0)("NEXTVAL")

            Dim newKYC As New RKYC
            newKYC.KYCSEQ = key
            newKYC.CUSTSEQ = CustSeq
            newKYC.KYCDATE = Now
            newKYC.ANSWERTYPE = 1
            newKYC.TRANSTYPE = 1

            newKYC.ACCOUNTNO = TxtAccNo.Text.Trim
            newKYC.ACCOUNTNAME = txtAccName.Text.Trim
            newKYC.WORKERSTATUS = "0"

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''Prachak '''''''''''''''''''''''''''''''''''''''''''''
            newKYC.ACCT_STATE = Me.lblACCT_STATE.Text
            '''''''Self BO'''''''''''''''
            If chkBO_SELF.Checked = True Then
                newKYC.FLAG_SELF_BO = "Y"
            Else
                newKYC.FLAG_SELF_BO = "N"
            End If
            ''''BO Other ''''''''''''''''''
            If chkBO_OTH.Checked = True Then
                newKYC.FLAG_OTHP_BO = "Y"
            Else
                newKYC.FLAG_OTHP_BO = "N"
            End If
            ''''Active'''''''''''''''''''''''
            newKYC.ACTIVE = Me.lblACTIVE.Text
            ''''CustType'''''''''''''''''''''
            newKYC.CUSTTYPE = lvsCustType
            newKYC.F_JOIN_ACCT = Me.lblF_JOIN_ACCT.Text
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


            'Dim intAns1 As Integer = 0
            'Dim intAns2 As Integer = 0

            'If chkDAcc1.Checked = True Then
            '    newKYC.ANSWER101 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER101 = 1
            'End If

            'If chkDAcc2.Checked = True Then
            '    newKYC.ANSWER102 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER102 = 1
            'End If
            'If chkDAcc3.Checked = True Then
            '    newKYC.ANSWER103 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER103 = 1
            'End If
            'If chkDAcc4.Checked = True Then
            '    newKYC.ANSWER104 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER104 = 1
            'End If
            'If chkDAcc5.Checked = True Then
            '    newKYC.ANSWER105 = 0
            '    newKYC.ANSWER199 = txtDAccOther.Text.Trim
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER105 = 1
            'End If



            'If chkDSource1.Checked = True Then
            '    newKYC.ANSWER201 = 0
            '    intAns2 += 1
            'Else
            '    newKYC.ANSWER201 = 1
            'End If
            'If chkDSource2.Checked = True Then
            '    newKYC.ANSWER202 = 0
            '    intAns2 += 1
            'Else
            '    newKYC.ANSWER202 = 1
            'End If
            'If chkDSource3.Checked = True Then
            '    newKYC.ANSWER203 = 0
            '    intAns2 += 1
            'Else
            '    newKYC.ANSWER203 = 1
            'End If
            'If chkDSource4.Checked = True Then
            '    newKYC.ANSWER204 = 0
            '    intAns2 += 1
            'Else
            '    newKYC.ANSWER204 = 1
            'End If
            'If chkDSource5.Checked = True Then
            '    newKYC.ANSWER205 = 0
            '    intAns2 += 1
            'Else
            'newKYC.ANSWER205 = 1
            'End If
            'If chkDSource6.Checked = True Then
            '    newKYC.ANSWER206 = 0
            '    newKYC.ANSWER299 = txtDSourceOther.Text.Trim
            '    intAns2 += 1
            'Else
            '    newKYC.ANSWER206 = 1
            'End If


            newKYC.ANSWER301 = ddlDDeposit.SelectedValue
            newKYC.ANSWER401 = ddlDMoney.SelectedValue


            If PanelDepositSactionC.Visible = True Then

                '    If chkDAsset1.Checked = True Then
                '        newKYC.ASSET1 = 0
                '    Else
                '        newKYC.ASSET1 = 1
                '    End If
                '    If chkDAsset2.Checked = True Then
                '        newKYC.ASSET2 = 0
                '    Else
                '        newKYC.ASSET2 = 1
                '    End If
                '    If chkDAsset3.Checked = True Then
                '        newKYC.ASSET3 = 0
                '    Else
                '        newKYC.ASSET3 = 1
                '    End If
                '    If chkDAsset4.Checked = True Then
                '        newKYC.ASSET4 = 0
                '    Else
                '        newKYC.ASSET4 = 1
                '    End If
                '    If chkDAsset5.Checked = True Then
                '        newKYC.ASSET5 = 0
                '    Else
                '        newKYC.ASSET5 = 1
                '    End If
                '    If chkDAsset6.Checked = True Then
                '        newKYC.ASSET6 = 0
                '        newKYC.ASSETOTHER = txtDAssetOther.Text
                '    Else
                '        newKYC.ASSET6 = 1
                '    End If

                '    If txtDValue.Text = "" Then
                '        newKYC.TOTALASSET = Nothing
                '    Else
                '        clsMoney = New clsMoney
                '        newKYC.TOTALASSET = clsMoney.deleteComma(txtDValue.Text.Trim)
                '        clsMoney = Nothing
                '    End If


                '    newKYC.APPROVECODE = ddlDApprove.SelectedValue
                '    newKYC.APPROVENAME = txtDApproveNo.Text.Trim
                '    newKYC.APPROVENO = txtDApproveNo.Text.Trim
                '    If txtDApproveDate.Text = "" Then
                '        newKYC.APPROVEDATE = Nothing
                '    Else
                '        Dim clsFormatDate As clsDateFormat = New clsDateFormat
                '        newKYC.APPROVEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDApproveDate.Text)
                '        clsFormatDate = Nothing
                '    End If

                '    'If ddlDApprove.SelectedValue = 1 Then
                '    '    newKYC.KYCCOMPLETE = "N"
                '    'Else
                '    If intAns1 = 0 Or intAns2 = 0 Or ddlDDeposit.SelectedIndex = 0 Or ddlDMoney.SelectedIndex = 0 Then
                '        newKYC.KYCCOMPLETE = "N"
                '    Else
                '        newKYC.KYCCOMPLETE = "Y" 'ถือว่าทำ KYC สมบูรณ์แล้ว
                '    End If

                '    'End If
                'Else
                '    If strCdd = "1" Then
                '        If intAns1 = 0 Or intAns2 = 0 Or ddlDDeposit.SelectedIndex = 0 Or ddlDMoney.SelectedIndex = 0 Then
                '            newKYC.KYCCOMPLETE = "N"
                '        Else
                '            newKYC.KYCCOMPLETE = "Y" 'ถือว่าทำ KYC สมบูรณ์แล้ว
                '        End If
                '    Else
                '        newKYC.KYCCOMPLETE = ""
                '    End If

            End If


            If Request.QueryString("KYC") = 1 Then
                newKYC.DEPUPDATE = "D"
            ElseIf Request.QueryString("KYC") = 2 Then
                newKYC.DEPUPDATE = "L"
            ElseIf Request.QueryString("KYC") = 3 Then
                newKYC.DEPUPDATE = "P"
            End If


            newKYC.BRANCHCODE = clsSessionMenuRight.getBranchCode
            newKYC.ZONECODE = clsSessionMenuRight.getZoneCode
            newKYC.DEPTCODE = clsSessionMenuRight.getDeptCode
            newKYC.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight

            newKYC.CREATEBY = clsSessionMenuRight.getUserName
            newKYC.CREATEDATE = Now.ToShortDateString
            newKYC.UPDATEBY = clsSessionMenuRight.getUserName
            newKYC.UPDATEDATE = Now.ToShortDateString


            KYCEntity.AddToRKYC(newKYC)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub saveUpdateKYCLoan()
        Dim lvsCustType As Integer = Session("KYC")
        Try
            Dim intKycSeq As Integer = hdfKYCSeq.Value

            Dim updateKYC = (From k In KYCEntity.RKYC
                           Where k.CUSTSEQ = CustSeq And k.KYCSEQ = intKycSeq And k.ANSWERTYPE = 3
                           Select k).First()

            'updateKYC.CHECKNAME = ddlCheckName.SelectedValue
            'updateKYC.CHECKADDRESS = ddlCheckAddress.SelectedValue

            updateKYC.ACCOUNTNO = TxtAccNo.Text.Trim
            updateKYC.ACCOUNTNAME = txtAccName.Text.Trim
            updateKYC.WORKERSTATUS = "0"

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''Prachak '''''''''''''''''''''''''''''''''''''''''''''
            updateKYC.ACCT_STATE = Me.lblACCT_STATE.Text
            '''''''Self BO'''''''''''''''
            If chkBO_SELF.Checked = True Then
                updateKYC.FLAG_SELF_BO = "Y"
            Else
                updateKYC.FLAG_SELF_BO = "N"
            End If
            ''''BO Other ''''''''''''''''''
            If chkBO_OTH.Checked = True Then
                updateKYC.FLAG_OTHP_BO = "Y"
            Else
                updateKYC.FLAG_OTHP_BO = "N"
            End If
            ''''Active'''''''''''''''''''''''
            updateKYC.ACTIVE = Me.lblACTIVE.Text
            ''''CustType '''''''''''''''''''''''
            updateKYC.CUSTTYPE = lvsCustType
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


            '     Dim intAns1 As Integer = 0
            'If chkLAcc1.Checked = True Then
            '    updateKYC.ANSWER101 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER101 = 1
            'End If
            'If chkLAcc2.Checked = True Then
            '    updateKYC.ANSWER102 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER102 = 1
            'End If
            'If chkLAcc3.Checked = True Then
            '    updateKYC.ANSWER103 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER103 = 1
            'End If
            'If chkLAcc4.Checked = True Then
            '    updateKYC.ANSWER104 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER104 = 1
            'End If
            'If chkLAcc5.Checked = True Then
            '    updateKYC.ANSWER105 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER105 = 1
            'End If
            'If chkLAcc6.Checked = True Then
            '    updateKYC.ANSWER106 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER106 = 1
            'End If
            'If chkLAcc7.Checked = True Then
            '    updateKYC.ANSWER107 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER107 = 1
            'End If
            'If chkLAcc8.Checked = True Then
            '    updateKYC.ANSWER108 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER108 = 1
            'End If
            'If chkLAcc9.Checked = True Then
            '    updateKYC.ANSWER109 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER109 = 1
            'End If
            'If chkLAcc10.Checked = True Then
            '    updateKYC.ANSWER110 = 0
            '    intAns1 += 1
            '    updateKYC.ANSWER199 = txtLAccOther.Text.Trim
            'Else
            '    updateKYC.ANSWER110 = 1
            'End If


            'If PanelDepositSactionC.Visible = True Then

            '    If chkDAsset1.Checked = True Then
            '        updateKYC.ASSET1 = 0
            '    Else
            '        updateKYC.ASSET1 = 1
            '    End If
            '    If chkDAsset2.Checked = True Then
            '        updateKYC.ASSET2 = 0
            '    Else
            '        updateKYC.ASSET2 = 1
            '    End If
            '    If chkDAsset3.Checked = True Then
            '        updateKYC.ASSET3 = 0
            '    Else
            '        updateKYC.ASSET3 = 1
            '    End If
            '    If chkDAsset4.Checked = True Then
            '        updateKYC.ASSET4 = 0
            '    Else
            '        updateKYC.ASSET4 = 1
            '    End If
            '    If chkDAsset5.Checked = True Then
            '        updateKYC.ASSET5 = 0
            '    Else
            '        updateKYC.ASSET5 = 1
            '    End If
            '    If chkDAsset6.Checked = True Then
            '        updateKYC.ASSET6 = 0
            '        updateKYC.ASSETOTHER = txtDAssetOther.Text
            '    Else
            '        updateKYC.ASSET6 = 1
            '    End If

            '    If txtDValue.Text = "" Then
            '        updateKYC.TOTALASSET = Nothing
            '    Else
            '        clsMoney = New clsMoney
            '        updateKYC.TOTALASSET = clsMoney.deleteComma(txtDValue.Text.Trim)
            '        clsMoney = Nothing
            '    End If


            '    updateKYC.APPROVECODE = ddlDApprove.SelectedValue
            '    updateKYC.APPROVENAME = txtDApproveNo.Text.Trim
            '    updateKYC.APPROVENO = txtDApproveNo.Text.Trim
            '    If txtDApproveDate.Text = "" Then
            '        updateKYC.APPROVEDATE = Nothing
            '    Else
            '        Dim clsFormatDate As clsDateFormat = New clsDateFormat
            '        updateKYC.APPROVEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDApproveDate.Text)
            '        clsFormatDate = Nothing
            '    End If
            '    'If ddlDApprove.SelectedValue = 1 Then
            '    '    updateKYC.KYCCOMPLETE = "N"
            '    'Else
            '    If intAns1 = 0 Then
            '        updateKYC.KYCCOMPLETE = "N"
            '    Else
            '        updateKYC.KYCCOMPLETE = "Y" 'ถือว่าทำ KYC สมบูรณ์แล้ว
            '    End If

            '    'End If
            'Else
            '    If strCdd = "1" Then

            '        If intAns1 = 0 Then
            '            updateKYC.KYCCOMPLETE = "N"
            '        Else
            '            updateKYC.KYCCOMPLETE = "Y"
            '        End If
            '    Else
            '        updateKYC.KYCCOMPLETE = ""
            '    End If

            'End If


            If Request.QueryString("KYC") = 1 Then
                updateKYC.DEPUPDATE = "D"
            ElseIf Request.QueryString("KYC") = 2 Then
                updateKYC.DEPUPDATE = "L"
            ElseIf Request.QueryString("KYC") = 3 Then
                updateKYC.DEPUPDATE = "P"
            End If

            updateKYC.BRANCHCODE = clsSessionMenuRight.getBranchCode
            updateKYC.ZONECODE = clsSessionMenuRight.getZoneCode
            updateKYC.DEPTCODE = clsSessionMenuRight.getDeptCode
            updateKYC.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight

            updateKYC.UPDATEBY = clsSessionMenuRight.getUserName
            updateKYC.UPDATEDATE = Now.ToShortDateString
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub saveNewKYCLoan()
        Dim lvsCustType As Integer = Session("KYC")
        Try
            If ds.Tables.Contains("GENKYC") Then
                ds.Tables.Remove("GENKYC")
            End If

            Dim sql As String = "select " & System.Configuration.ConfigurationSettings.AppSettings("SequentRKYC_S") & " from dual"
            ds.Tables.Add(clsDatabase.QueryDataSet(sql, "GENKYC").Tables("GENKYC").Copy)
            Dim key As Integer = ds.Tables("GENKYC").Rows(0)("NEXTVAL")

            Dim newKYC As New RKYC
            newKYC.KYCSEQ = key
            newKYC.CUSTSEQ = CustSeq
            newKYC.KYCDATE = Now
            newKYC.ANSWERTYPE = 3
            newKYC.TRANSTYPE = 1
            newKYC.ACCOUNTNO = TxtAccNo.Text.Trim
            newKYC.ACCOUNTNAME = txtAccName.Text.Trim
            newKYC.WORKERSTATUS = "0"

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''Prachak '''''''''''''''''''''''''''''''''''''''''''''
            newKYC.ACCT_STATE = Me.lblACCT_STATE.Text
            '''''''Self BO'''''''''''''''
            If chkBO_SELF.Checked = True Then
                newKYC.FLAG_SELF_BO = "Y"
            Else
                newKYC.FLAG_SELF_BO = "N"
            End If
            ''''BO Other ''''''''''''''''''
            If chkBO_OTH.Checked = True Then
                newKYC.FLAG_OTHP_BO = "Y"
            Else
                newKYC.FLAG_OTHP_BO = "N"
            End If
            ''''Active'''''''''''''''''''''''
            newKYC.ACTIVE = Me.lblACTIVE.Text
            ''''CustType'''''''''''''''''''''
            newKYC.CUSTTYPE = lvsCustType

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            '      Dim intAns1 As Integer = 0

            'If chkLAcc1.Checked = True Then
            '    newKYC.ANSWER101 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER101 = 1
            'End If
            'If chkLAcc2.Checked = True Then
            'newKYC.ANSWER102 = 0
            'intAns1 += 1
            'Else
            'newKYC.ANSWER102 = 1
            'End If
            'If chkLAcc3.Checked = True Then
            '    newKYC.ANSWER103 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER103 = 1
            'End If
            'If chkLAcc4.Checked = True Then
            '    newKYC.ANSWER104 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER104 = 1
            'End If
            'If chkLAcc5.Checked = True Then
            '    newKYC.ANSWER105 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER105 = 1
            'End If
            'If chkLAcc6.Checked = True Then
            '    newKYC.ANSWER106 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER106 = 1
            'End If
            'If chkLAcc7.Checked = True Then
            '    newKYC.ANSWER107 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER107 = 1
            'End If
            'If chkLAcc8.Checked = True Then
            '    newKYC.ANSWER108 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER108 = 1
            'End If
            'If chkLAcc9.Checked = True Then
            '    newKYC.ANSWER109 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER109 = 1
            'End If
            'If chkLAcc10.Checked = True Then
            '    newKYC.ANSWER110 = 0
            '    intAns1 += 1
            '    newKYC.ANSWER199 = txtLAccOther.Text.Trim
            'Else
            '    newKYC.ANSWER110 = 1
            'End If


            'If PanelDepositSactionC.Visible = True Then

            '    If chkDAsset1.Checked = True Then
            '        newKYC.ASSET1 = 0
            '    Else
            '        newKYC.ASSET1 = 1
            '    End If
            '    If chkDAsset2.Checked = True Then
            '        newKYC.ASSET2 = 0
            '    Else
            '        newKYC.ASSET2 = 1
            '    End If
            '    If chkDAsset3.Checked = True Then
            '        newKYC.ASSET3 = 0
            '    Else
            '        newKYC.ASSET3 = 1
            '    End If
            '    If chkDAsset4.Checked = True Then
            '        newKYC.ASSET4 = 0
            '    Else
            '        newKYC.ASSET4 = 1
            '    End If
            '    If chkDAsset5.Checked = True Then
            '        newKYC.ASSET5 = 0
            '    Else
            '        newKYC.ASSET5 = 1
            '    End If
            '    If chkDAsset6.Checked = True Then
            '        newKYC.ASSET6 = 0
            '        newKYC.ASSETOTHER = txtDAssetOther.Text
            '    Else
            '        newKYC.ASSET6 = 1
            '    End If

            '    If txtDValue.Text = "" Then
            '        newKYC.TOTALASSET = Nothing
            '    Else
            '        clsMoney = New clsMoney
            '        newKYC.TOTALASSET = clsMoney.deleteComma(txtDValue.Text.Trim)
            '        clsMoney = Nothing
            '    End If


            '    newKYC.APPROVECODE = ddlDApprove.SelectedValue
            '    newKYC.APPROVENAME = txtDApproveNo.Text.Trim
            '    newKYC.APPROVENO = txtDApproveNo.Text.Trim
            '    If txtDApproveDate.Text = "" Then
            '        newKYC.APPROVEDATE = Nothing
            '    Else
            '        Dim clsFormatDate As clsDateFormat = New clsDateFormat
            '        newKYC.APPROVEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDApproveDate.Text)
            '        clsFormatDate = Nothing
            '    End If
            '    'If ddlDApprove.SelectedValue = 1 Then
            '    '    newKYC.KYCCOMPLETE = "N"
            '    'Else
            '    'If intAns1 = 0 Then
            '    '    newKYC.KYCCOMPLETE = "N"
            '    'Else
            '    '    newKYC.KYCCOMPLETE = "Y" 'ถือว่าทำ KYC สมบูรณ์แล้ว
            '    'End If

            '    'End If
            'Else
            '    If strCdd = "1" Then
            '        If intAns1 = 0 Then
            '            newKYC.KYCCOMPLETE = "N"
            '        Else
            '            newKYC.KYCCOMPLETE = "Y"
            '        End If
            '    Else
            '        newKYC.KYCCOMPLETE = ""
            '    End If

            'End If

            If Request.QueryString("KYC") = 1 Then
                newKYC.DEPUPDATE = "D"
            ElseIf Request.QueryString("KYC") = 2 Then
                newKYC.DEPUPDATE = "L"
            ElseIf Request.QueryString("KYC") = 3 Then
                newKYC.DEPUPDATE = "P"
            End If

            newKYC.BRANCHCODE = clsSessionMenuRight.getBranchCode
            newKYC.ZONECODE = clsSessionMenuRight.getZoneCode
            newKYC.DEPTCODE = clsSessionMenuRight.getDeptCode
            newKYC.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight

            newKYC.CREATEBY = clsSessionMenuRight.getUserName
            newKYC.CREATEDATE = Now.ToShortDateString
            newKYC.UPDATEBY = clsSessionMenuRight.getUserName
            newKYC.UPDATEDATE = Now.ToShortDateString

            KYCEntity.AddToRKYC(newKYC)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub saveUpdateKYCPN()
        Dim lvsCustType As Integer = Session("KYC")
        Try
            Dim intKycSeq As Integer = hdfKYCSeq.Value
            Dim updateKYC = (From k In KYCEntity.RKYC
                           Where k.CUSTSEQ = CustSeq And k.KYCSEQ = intKycSeq And k.ANSWERTYPE = 5
                           Select k).First()

            'updateKYC.CHECKNAME = ddlCheckName.SelectedValue
            'updateKYC.CHECKADDRESS = ddlCheckAddress.SelectedValue

            updateKYC.ACCOUNTNO = TxtAccNo.Text.Trim
            updateKYC.ACCOUNTNAME = txtAccName.Text.Trim
            updateKYC.WORKERSTATUS = "0"

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''Prachak '''''''''''''''''''''''''''''''''''''''''''''
            updateKYC.ACCT_STATE = Me.lblACCT_STATE.Text
            '''''''Self BO'''''''''''''''
            If chkBO_SELF.Checked = True Then
                updateKYC.FLAG_SELF_BO = "Y"
            Else
                updateKYC.FLAG_SELF_BO = "N"
            End If
            ''''BO Other ''''''''''''''''''
            If chkBO_OTH.Checked = True Then
                updateKYC.FLAG_OTHP_BO = "Y"
            Else
                updateKYC.FLAG_OTHP_BO = "N"
            End If
            ''''Active'''''''''''''''''''''''
            updateKYC.ACTIVE = Me.lblACTIVE.Text
            ''''CustType '''''''''''''''''''''''
            updateKYC.CUSTTYPE = lvsCustType
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


            'Dim intAns1 As Integer = 0
            'Dim intSource As Integer = 0

            'If chkPAcc1.Checked = True Then
            '    updateKYC.ANSWER101 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER101 = 1
            'End If
            'If chkPAcc2.Checked = True Then
            '    updateKYC.ANSWER102 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER102 = 1
            'End If
            'If chkPAcc3.Checked = True Then
            '    updateKYC.ANSWER103 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER103 = 1
            'End If
            'If chkPAcc4.Checked = True Then
            '    updateKYC.ANSWER104 = 0
            '    intAns1 += 1
            'Else
            '    updateKYC.ANSWER104 = 1
            'End If
            'If chkPAcc5.Checked = True Then
            '    updateKYC.ANSWER105 = 0
            '    intAns1 += 1
            '    updateKYC.ANSWER199 = txtPAccOther.Text.Trim
            'Else
            '    updateKYC.ANSWER105 = 1
            'End If


            'If chkPSource1.Checked = True Then
            '    updateKYC.ANSWER201 = 0
            '    intSource += 1
            'Else
            '    updateKYC.ANSWER201 = 1
            'End If
            'If chkPSource2.Checked = True Then
            '    updateKYC.ANSWER202 = 0
            '    intSource += 1
            'Else
            '    updateKYC.ANSWER202 = 1
            'End If
            'If chkPSource3.Checked = True Then
            '    updateKYC.ANSWER203 = 0
            '    intSource += 1
            'Else
            '    updateKYC.ANSWER203 = 1
            'End If
            'If chkPSource4.Checked = True Then
            '    updateKYC.ANSWER204 = 0
            '    intSource += 1
            'Else
            '    updateKYC.ANSWER204 = 1
            'End If
            'If chkPSource5.Checked = True Then
            '    updateKYC.ANSWER205 = 0
            '    intSource += 1
            'Else
            '    updateKYC.ANSWER205 = 1
            'End If
            'If chkPSource6.Checked = True Then
            '    updateKYC.ANSWER206 = 0
            '    intSource += 1
            '    updateKYC.ANSWER299 = txtPSourceOther.Text.Trim
            'Else
            '    updateKYC.ANSWER206 = 1
            'End If

            updateKYC.ANSWER301 = ddlPDeposit.SelectedValue
            updateKYC.ANSWER401 = ddlPMoney.SelectedValue


            If PanelDepositSactionC.Visible = True Then

                If chkDAsset1.Checked = True Then
                    updateKYC.ASSET1 = 0
                Else
                    updateKYC.ASSET1 = 1
                End If
                If chkDAsset2.Checked = True Then
                    updateKYC.ASSET2 = 0
                Else
                    updateKYC.ASSET2 = 1
                End If
                If chkDAsset3.Checked = True Then
                    updateKYC.ASSET3 = 0
                Else
                    updateKYC.ASSET3 = 1
                End If
                If chkDAsset4.Checked = True Then
                    updateKYC.ASSET4 = 0
                Else
                    updateKYC.ASSET4 = 1
                End If
                If chkDAsset5.Checked = True Then
                    updateKYC.ASSET5 = 0
                Else
                    updateKYC.ASSET5 = 1
                End If
                If chkDAsset6.Checked = True Then
                    updateKYC.ASSET6 = 0
                    updateKYC.ASSETOTHER = txtDAssetOther.Text
                Else
                    updateKYC.ASSET6 = 1
                End If

                If txtDValue.Text = "" Then
                    updateKYC.TOTALASSET = Nothing
                Else
                    clsMoney = New clsMoney
                    updateKYC.TOTALASSET = clsMoney.deleteComma(txtDValue.Text.Trim)
                    clsMoney = Nothing
                End If


                updateKYC.APPROVECODE = ddlDApprove.SelectedValue
                updateKYC.APPROVENAME = txtDApproveNo.Text.Trim
                updateKYC.APPROVENO = txtDApproveNo.Text.Trim
                If txtDApproveDate.Text = "" Then
                    updateKYC.APPROVEDATE = Nothing
                Else
                    Dim clsFormatDate As clsDateFormat = New clsDateFormat
                    updateKYC.APPROVEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDApproveDate.Text)
                    clsFormatDate = Nothing
                End If
                'If ddlDApprove.SelectedValue = 1 Then
                '    updateKYC.KYCCOMPLETE = "N"
                'Else
                'If intAns1 = 0 Or intSource = 0 Or ddlPDeposit.SelectedIndex = 0 Or ddlPMoney.SelectedIndex = 0 Then
                '    updateKYC.KYCCOMPLETE = "N"
                'Else
                '    updateKYC.KYCCOMPLETE = "Y" 'ถือว่าทำ KYC สมบูรณ์แล้ว
                'End If



                'End If
            Else
                If strCdd = "1" Then
                    'If intAns1 = 0 Or intSource = 0 Or ddlPDeposit.SelectedIndex = 0 Or ddlPMoney.SelectedIndex = 0 Then
                    '    updateKYC.KYCCOMPLETE = "N"
                    'Else
                    '    updateKYC.KYCCOMPLETE = "Y" 'ถือว่าทำ KYC สมบูรณ์แล้ว
                    'End If
                Else
                    updateKYC.KYCCOMPLETE = ""
                End If

            End If

            If Request.QueryString("KYC") = 1 Then
                updateKYC.DEPUPDATE = "D"
            ElseIf Request.QueryString("KYC") = 2 Then
                updateKYC.DEPUPDATE = "L"
            ElseIf Request.QueryString("KYC") = 3 Then
                updateKYC.DEPUPDATE = "P"
            End If

            updateKYC.BRANCHCODE = clsSessionMenuRight.getBranchCode
            updateKYC.ZONECODE = clsSessionMenuRight.getZoneCode
            updateKYC.DEPTCODE = clsSessionMenuRight.getDeptCode
            updateKYC.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight

            updateKYC.UPDATEBY = clsSessionMenuRight.getUserName
            updateKYC.UPDATEDATE = Now.ToShortDateString
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub saveNewKYCPN()
        Dim lvsCustType As Integer = Session("KYC")
        Try
            If ds.Tables.Contains("GENKYC") Then
                ds.Tables.Remove("GENKYC")
            End If

            Dim sql As String = "select " & System.Configuration.ConfigurationSettings.AppSettings("SequentRKYC_S") & " from dual"
            ds.Tables.Add(clsDatabase.QueryDataSet(sql, "GENKYC").Tables("GENKYC").Copy)
            Dim key As Integer = ds.Tables("GENKYC").Rows(0)("NEXTVAL")

            Dim newKYC As New RKYC
            newKYC.KYCSEQ = key
            newKYC.CUSTSEQ = CustSeq
            newKYC.KYCDATE = Now
            newKYC.ANSWERTYPE = 5
            newKYC.TRANSTYPE = 1
            newKYC.ACCOUNTNO = TxtAccNo.Text.Trim
            newKYC.ACCOUNTNAME = txtAccName.Text.Trim
            newKYC.WORKERSTATUS = "0"

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''Prachak '''''''''''''''''''''''''''''''''''''''''''''
            newKYC.ACCT_STATE = Me.lblACCT_STATE.Text
            '''''''Self BO'''''''''''''''
            If chkBO_SELF.Checked = True Then
                newKYC.FLAG_SELF_BO = "Y"
            Else
                newKYC.FLAG_SELF_BO = "N"
            End If
            ''''BO Other ''''''''''''''''''
            If chkBO_OTH.Checked = True Then
                newKYC.FLAG_OTHP_BO = "Y"
            Else
                newKYC.FLAG_OTHP_BO = "N"
            End If
            ''''Active'''''''''''''''''''''''
            newKYC.ACTIVE = Me.lblACTIVE.Text
            ''''CustType'''''''''''''''''''''
            newKYC.CUSTTYPE = lvsCustType

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            'Dim intAns1 As Integer = 0
            'Dim intSource As Integer = 0


            'If chkDAcc1.Checked = True Then
            '    newKYC.ANSWER101 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER101 = 1
            'End If
            'If chkDAcc2.Checked = True Then
            '    newKYC.ANSWER102 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER102 = 1
            'End If
            'If chkDAcc3.Checked = True Then
            '    newKYC.ANSWER103 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER103 = 1
            'End If
            'If chkDAcc4.Checked = True Then
            '    newKYC.ANSWER104 = 0
            '    intAns1 += 1
            'Else
            '    newKYC.ANSWER104 = 1
            'End If
            'If chkDAcc5.Checked = True Then
            '    newKYC.ANSWER105 = 0
            '    intAns1 += 1
            '    newKYC.ANSWER199 = txtDAccOther.Text.Trim
            'Else
            '    newKYC.ANSWER105 = 1
            'End If

            'If chkDSource1.Checked = True Then
            '    newKYC.ANSWER201 = 0
            '    intSource += 1
            'Else
            '    newKYC.ANSWER201 = 1
            'End If
            'If chkDSource2.Checked = True Then
            '    newKYC.ANSWER202 = 0
            '    intSource += 1
            'Else
            '    newKYC.ANSWER202 = 1
            'End If
            'If chkDSource3.Checked = True Then
            '    newKYC.ANSWER203 = 0
            '    intSource += 1
            'Else
            '    newKYC.ANSWER203 = 1
            'End If
            'If chkDSource4.Checked = True Then
            '    newKYC.ANSWER204 = 0
            '    intSource += 1
            'Else
            '    newKYC.ANSWER204 = 1
            'End If
            'If chkDSource5.Checked = True Then
            '    newKYC.ANSWER205 = 0
            '    intSource += 1
            'Else
            '    newKYC.ANSWER205 = 1
            'End If
            'If chkDSource6.Checked = True Then
            '    newKYC.ANSWER206 = 0
            '    intSource += 1
            '    newKYC.ANSWER299 = txtDSourceOther.Text.Trim
            'Else
            '    newKYC.ANSWER206 = 1
            'End If

            newKYC.ANSWER301 = ddlDDeposit.SelectedValue
            newKYC.ANSWER401 = ddlDMoney.SelectedValue

            'If PanelDepositSactionC.Visible = True Then

            '    If chkDAsset1.Checked = True Then
            '        newKYC.ASSET1 = 0
            '    Else
            '        newKYC.ASSET1 = 1
            '    End If
            '    If chkDAsset2.Checked = True Then
            '        newKYC.ASSET2 = 0
            '    Else
            '        newKYC.ASSET2 = 1
            '    End If
            '    If chkDAsset3.Checked = True Then
            '        newKYC.ASSET3 = 0
            '    Else
            '        newKYC.ASSET3 = 1
            '    End If
            '    If chkDAsset4.Checked = True Then
            '        newKYC.ASSET4 = 0
            '    Else
            '        newKYC.ASSET4 = 1
            '    End If
            '    If chkDAsset5.Checked = True Then
            '        newKYC.ASSET5 = 0
            '    Else
            '        newKYC.ASSET5 = 1
            '    End If
            '    If chkDAsset6.Checked = True Then
            '        newKYC.ASSET6 = 0
            '        newKYC.ASSETOTHER = txtDAssetOther.Text
            '    Else
            '        newKYC.ASSET6 = 1
            '    End If

            '    If txtDValue.Text = "" Then
            '        newKYC.TOTALASSET = Nothing
            '    Else
            '        clsMoney = New clsMoney
            '        newKYC.TOTALASSET = clsMoney.deleteComma(txtDValue.Text.Trim)
            '        clsMoney = Nothing
            '    End If


            '    newKYC.APPROVECODE = ddlDApprove.SelectedValue
            '    newKYC.APPROVENAME = txtDApproveNo.Text.Trim
            '    newKYC.APPROVENO = txtDApproveNo.Text.Trim
            '    If txtDApproveDate.Text = "" Then
            '        newKYC.APPROVEDATE = Nothing
            '    Else
            '        Dim clsFormatDate As clsDateFormat = New clsDateFormat
            '        newKYC.APPROVEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDApproveDate.Text)
            '        clsFormatDate = Nothing
            '    End If
            '    'If ddlDApprove.SelectedValue = 1 Then
            '    '    newKYC.KYCCOMPLETE = "N"
            '    'Else
            '    If intAns1 = 0 Or intSource = 0 Or ddlPDeposit.SelectedIndex = 0 Or ddlPMoney.SelectedIndex = 0 Then
            '        newKYC.KYCCOMPLETE = "N"
            '    Else
            '        newKYC.KYCCOMPLETE = "Y" 'ถือว่าทำ KYC สมบูรณ์แล้ว
            '    End If


            '    'End If
            'Else
            '    If strCdd = "1" Then
            '        If intAns1 = 0 Or intSource = 0 Or ddlPDeposit.SelectedIndex = 0 Or ddlPMoney.SelectedIndex = 0 Then
            '            newKYC.KYCCOMPLETE = "N"
            '        Else
            '            newKYC.KYCCOMPLETE = "Y"
            '        End If

            '    Else
            '        newKYC.KYCCOMPLETE = ""
            '    End If

            'End If

            'If Request.QueryString("KYC") = 1 Then
            '    newKYC.DEPUPDATE = "D"
            'ElseIf Request.QueryString("KYC") = 2 Then
            '    newKYC.DEPUPDATE = "L"
            'ElseIf Request.QueryString("KYC") = 3 Then
            '    newKYC.DEPUPDATE = "P"
            'End If

            newKYC.BRANCHCODE = clsSessionMenuRight.getBranchCode
            newKYC.ZONECODE = clsSessionMenuRight.getZoneCode
            newKYC.DEPTCODE = clsSessionMenuRight.getDeptCode
            newKYC.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight

            newKYC.CREATEBY = clsSessionMenuRight.getUserName
            newKYC.CREATEDATE = Now.ToShortDateString
            newKYC.UPDATEBY = clsSessionMenuRight.getUserName
            newKYC.UPDATEDATE = Now.ToShortDateString

            KYCEntity.AddToRKYC(newKYC)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub SaveLog(ByVal index As Integer)
        Try
            Dim program As String = ""
            If CInt(Request.QueryString("KYC")) = 1 Then
                program = "M11"
            ElseIf CInt(Request.QueryString("KYC")) = 2 Then
                program = "M21"
            ElseIf CInt(Request.QueryString("KYC")) = 3 Then
                program = "M31"
            ElseIf CInt(Request.QueryString("KYC")) = 5 Then
                program = "M51"
            Else
                program = "M41"
            End If

            Dim desc As String = ""
            If index = 1 Then
                desc = "พิมพ์ฟอร์ม KYC"
            ElseIf index = 2 Then
                desc = "พิมพ์ผลประเมินความเสี่ยง"
            ElseIf index = 3 Then
                desc = "บันทึก ข้อมูล KYC (" + ddlUniqueType.SelectedItem.Text + " " + txtUniqueID.Text + ")"
            ElseIf index = 4 Then
                desc = "บันทึก แก้ไข ข้อมูล KYC (" + ddlUniqueType.SelectedItem.Text + " " + txtUniqueID.Text + ")"
            End If

            Dim clsLogTransaction As New clsLogTransaction
            If index < 3 Then
                clsLogTransaction.saveLogTransaction(txtUniqueID.Text.Trim, clsSessionMenuRight.getUserName, 2, desc, program)
            Else
                clsLogTransaction.saveLogTransaction(txtUniqueID.Text.Trim, clsSessionMenuRight.getUserName, index, desc, program)
            End If

            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region

    Protected Sub btnCDD_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCDD.Click
        If CustSeq = 0 Then
            Response.Redirect("IndividualCDD.aspx?KYC=" & Request.QueryString("KYC") & "&TypeKYC=1&CUSTSEQ=" & CustSeq & "&Back=1")
        Else
            Response.Redirect("IndividualCDD.aspx?KYC=" & Request.QueryString("KYC") & "&TypeKYC=2&CUSTSEQ=" & CustSeq & "")
        End If

    End Sub

    Protected Sub btnKYC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnKYC.Click
        Try
            If CInt(Session("KYC")) = 5 Then
                hdfKYCSeq.Value = "0"
            End If

            If hdfKYCSeq.Value = "" Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                          UpdatePanel1.GetType(), _
                                                          "clientScript", _
                                                          "alert('" + "กรุณาเลือกรายการที่จะพิมพ์" + "')", _
                                                          True)

                Exit Sub
            End If
            SaveLog(1)
            If CInt(Session("KYC")) = 1 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC1T_01.aspx?CUSTSEQ=" & CInt(CustSeq) & "&Type=" & CInt(Session("KYC")) & "&KYCSEQ=" & hdfKYCSeq.Value & "','_blank','scrollbars=1,Width:1000px, Height:600px')", True)
            ElseIf CInt(Session("KYC")) = 2 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC2T_01.aspx?CUSTSEQ=" & CInt(CustSeq) & "&KYCSEQ=" & hdfKYCSeq.Value & "','_blank','scrollbars=1,Width:1000px, Height:600px')", True)
            ElseIf CInt(Session("KYC")) = 3 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC3T_01.aspx?CUSTSEQ=" & CInt(CustSeq) & "&Type=" & CInt(Session("KYC")) & "&KYCSEQ=" & hdfKYCSeq.Value & "','_blank','scrollbars=1,Width:1000px, Height:600px')", True)
            ElseIf CInt(Session("KYC")) = 5 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC4T_01.aspx?CUSTSEQ=" & CInt(CustSeq) & "','_blank','scrollbars=1,Width:1000px, Height:600px')", True)

            End If
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)

        End Try
    End Sub

    Protected Sub ddlFormalProvice_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlFormalProvince.SelectedIndexChanged
        Dim clsDropDown As New clsMasterDropDown

        If Not ddlFormalProvince.SelectedIndex = 0 Then
            clsDropDown.setAmphor(ddlFormalAmphor, ProviceCode:=ddlFormalProvince.SelectedValue)
        Else
            ddlFormalAmphor.Items.Clear()
            ddlFormalTambol.Items.Clear()
        End If
    End Sub

    Protected Sub ddlWorkProvice_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlWorkProvice.SelectedIndexChanged
        Dim clsDropDown As New clsMasterDropDown

        If Not ddlWorkProvice.SelectedIndex = 0 Then
            clsDropDown.setAmphor(ddlWorkAmphor, ProviceCode:=ddlWorkProvice.SelectedValue)
        Else
            ddlWorkAmphor.Items.Clear()
            ddlWorkTambol.Items.Clear()
        End If
    End Sub

    Protected Sub ddlContactProvice_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTBR_Province.SelectedIndexChanged
        Dim clsDropDown As New clsMasterDropDown

        If Not ddlTBR_Province.SelectedIndex = 0 Then
            clsDropDown.setAmphor(ddlTBR_Amphor, ProviceCode:=ddlTBR_Province.SelectedValue)
        Else
            ddlTBR_Amphor.Items.Clear()
            ddlTBR_Tambol.Items.Clear()
        End If
    End Sub

    Protected Sub ddlFormalAmphor_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlFormalAmphor.SelectedIndexChanged
        Dim clsDropDown As New clsMasterDropDown

        If Not ddlFormalAmphor.SelectedIndex = 0 Then
            clsDropDown.setTambol(ddlFormalTambol, AmphorCode:=ddlFormalAmphor.SelectedValue)
        Else
            ddlFormalTambol.Items.Clear()
        End If
    End Sub

    Protected Sub ddlWorkAmphor_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlWorkAmphor.SelectedIndexChanged
        Dim clsDropDown As New clsMasterDropDown

        If Not ddlWorkAmphor.SelectedIndex = 0 Then
            clsDropDown.setTambol(ddlWorkTambol, AmphorCode:=ddlWorkAmphor.SelectedValue)
        Else
            ddlWorkTambol.Items.Clear()
        End If
    End Sub

    Protected Sub ddlContactAmphor_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTBR_Amphor.SelectedIndexChanged
        Dim clsDropDown As New clsMasterDropDown

        If Not ddlTBR_Amphor.SelectedIndex = 0 Then
            clsDropDown.setTambol(ddlTBR_Tambol, AmphorCode:=ddlTBR_Amphor.SelectedValue)
        Else
            ddlTBR_Tambol.Items.Clear()
        End If
    End Sub

    Protected Function concatAddress(ByVal strTextAddrNo As String, ByVal strTextMoo As String, _
                                ByVal strTextSoi As String, ByVal strTextStreet As String, _
                                ByVal strTextTambol As String, ByVal strTextAmphor As String, _
                                ByVal strTextProvince As String, ByVal strTextZip As String) As String

        Dim strFullAddress As String = ""


        Dim strAddressNo As String = ""
        Dim strMoo As String = " หมู่ "
        Dim strSoi As String = " ซอย "
        Dim strStreet As String = " ถนน "
        Dim strTamBol As String = " แขวง/ตำบล "
        Dim strAmphor As String = " เขต/อำเภอ "
        Dim strProvince As String = " จังหวัด "
        Dim strZip As String = " รหัสไปรษณีย์ "

        strAddressNo = If(strTextAddrNo.Trim = "", "-", strTextAddrNo.Trim)
        strMoo &= If(strTextMoo.Trim = "", "-", strTextMoo.Trim)
        strSoi &= If(strTextSoi.Trim = "", "-", strTextSoi.Trim)
        strStreet &= If(strTextStreet.Trim = "", "-", strTextStreet.Trim)
        strTamBol &= strTextTambol.Trim
        strAmphor &= strTextAmphor.Trim
        strProvince &= strTextProvince.Trim
        strZip &= If(strTextZip.Trim = "", "-", strTextZip.Trim)

        strFullAddress = strAddressNo & strMoo & strSoi & strStreet & strTamBol & strAmphor & strProvince & strZip

        Return strFullAddress
    End Function


    Protected Sub btnSearchAcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchAcc.Click
        Dim intKYC As Integer = CInt(Request.QueryString("KYC"))
        If intKYC = 1 Then
            intKYC = 1
        ElseIf intKYC = 2 Then
            intKYC = 3
        ElseIf intKYC = 3 Then
            intKYC = 5
        End If
        Dim strAcc As String = TxtAccNo.Text
        'Dim qryKYC = (From kyc In KYCEntity.RKYC
        '                  Where kyc.ACCOUNTNO = strAcc And kyc.ANSWERTYPE = intKYC
        '                  Select kyc.ACCOUNTNO, kyc.ACCOUNTNAME).ToList

        If hdfKYCSeq.Value = "" Then
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                      UpdatePanel1.GetType(), _
                                                      "clientScript", _
                                                      "alert('" + "กรุณาเลือกรายการที่จะทำแบบสอบถามเพิ่มเติม" + "')", _
                                                      True)

            Exit Sub
        End If
        Dim intkycSeq As Integer = hdfKYCSeq.Value
        If Request.QueryString("KYC") = 1 Then
            BindingDataKYCDeposit(strAcc)
        ElseIf Request.QueryString("KYC") = 2 Then
            BindingDataKYCLoan(strAcc)
        ElseIf Request.QueryString("KYC") = 3 Then
            BindingDataKYCPN(strAcc)
        End If

        If intCountSearch = 0 Then
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                          UpdatePanel1.GetType(), _
                                                          "clientScript", _
                                                          "alert('" + "ไม่พบข้อมูล" + "')", _
                                                          True)
            TxtAccNo.Enabled = True
            txtAccName.Enabled = True
        Else

            TxtAccNo.Enabled = False
            txtAccName.Enabled = False

        End If

        'If Not qryKYC.Count = 0 Then
        '    TxtAccNo.Text = qryKYC(0).ACCOUNTNO
        '    txtAccName.Text = qryKYC(0).ACCOUNTNAME
        'Else
        '    ScriptManager.RegisterStartupScript(UpdatePanel1, _
        '                                                  UpdatePanel1.GetType(), _
        '                                                  "clientScript", _
        '                                                  "alert('" + "ไม่พบข้อมูล" + "')", _
        '                                                  True)
        'End If


    End Sub

    Protected Sub grdShowAccount_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdShowAccount.RowCommand
        If (e.CommandName = "Acc_Import") Then

            If Not String.IsNullOrEmpty(lbCUSTSEQ.Text) Then
                Try
                    If (grdShowAccount.SelectedIndex >= -1) Then
                        Dim accountNO As String = grdShowAccount.Rows(e.CommandArgument).Cells(1).Text
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "window.open('../Administrator/KycFileScan.aspx?CUSTSEQ=" & lbCUSTSEQ.Text & "&accountNO=" & accountNO & "','_blank','scrollbars=1,Width:800px, Height:600px')", True)
                    End If
                Catch ex As Exception
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & ex.Message & "')", True)
                    condition = False
                End Try
            End If
        End If

        If (e.CommandName = "Acc_View") Then


        End If
    End Sub

    'Protected Sub btnSaveAcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSaveAcc.Click
    '    If Not (hdfKYCSeq.Value = Nothing Or hdfKYCSeq.Value = "") Then
    '        Dim intKYCSeq As Integer = hdfKYCSeq.Value

    '        Dim sqlUpdateKYC = (From tblKYC In KYCEntity.RKYC Where tblKYC.KYCSEQ = intKYCSeq And tblKYC.CUSTSEQ = CustSeq).First
    '        sqlUpdateKYC.ACCOUNTNO = TxtAccNo.Text.Trim
    '        sqlUpdateKYC.ACCOUNTNAME = txtAccName.Text.Trim
    '        sqlUpdateKYC.WORKERSTATUS = "0"

    '        KYCEntity.SaveChanges()

    '        resetData()
    '        loadKYCAccount()
    '    Else


    '    End If
    'End Sub

    Protected Sub grdShowAccount_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdShowAccount.RowDataBound
        If (e.Row.RowType.ToString = "DataRow") Then
            Dim lblAppe As Label = CType(e.Row.FindControl("label38"), Label)
            If (lblAppe.Text = "") Then
                lblAppe.Text = " - "
            ElseIf (lblAppe.Text = 1) Then
                lblAppe.Text = " รออนุมัติ "
            ElseIf (lblAppe.Text = 2) Then
                lblAppe.Text = " อนุมัติ "
            ElseIf (lblAppe.Text = 3) Then
                lblAppe.Text = " ไม่อนุม้ติ "
            End If
        End If
    End Sub

    Protected Sub grdShowAccount_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdShowAccount.SelectedIndexChanged
        If (grdShowAccount.SelectedIndex = intBeforeItemIndex) Then
            grdShowAccount.SelectedIndex = -1
            ''''''''''''''''''''''''''''''
            Me.resetData()
            Me.chkBO_SELF.Enabled = False : Me.chkBO_SELF.Checked = False : Me.btAddBo_SELF.Enabled = False
            Me.chkBO_OTH.Enabled = False : Me.chkBO_OTH.Checked = False

            Me.btDelAcc.Enabled = False

            Me.btAddAcc.Enabled = True
            Me.btnPOP_CBS.Enabled = True
            Me.chkJoin_Account.Enabled = True

            Me.ddDAcc.Enabled = False
            Me.btAddDAcc.Enabled = False
            Me.btDelDAcc.Enabled = False
            Me.ddDSource.Enabled = False
            Me.btAddDSource.Enabled = False
            Me.btDelDSource.Enabled = False
            Me.ddLAcc.Enabled = False
            Me.btAddLAcc.Enabled = False
            Me.btDelLAcc.Enabled = False

            Me.ddPAcc.Enabled = False
            Me.btAddPAcc.Enabled = False
            Me.btDelPAcc.Enabled = False

            Me.ddPSource.Enabled = False
            Me.btAddPSource.Enabled = False
            Me.btDelPSource.Enabled = False

            Me.lblKYCSEQ.Text = ""

            '''''''''''''''''''''''''''''

            btnSave.Visible = False
            btnDeleteAcc.Visible = False


        Else
            If TypeKYC = 4 Then
                btnSave.Visible = False
            Else
                btnSave.Visible = True
            End If

            If grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text.Trim = "" Then
                btnDeleteAcc.Visible = True
            Else
                btnDeleteAcc.Visible = False
            End If

            '''''''''
            Me.btAddAcc.Enabled = False
            Me.btnPOP_CBS.Enabled = False
            Me.chkJoin_Account.Enabled = False
            Me.TxtAccNo.Enabled = False
            Me.txtAccName.Enabled = False

            clearPanel()
            Dim strKYCSEQ As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblKYCSeq"), Label).Text
            Dim strAccName As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblAccountName"), Label).Text


            ''''Prachak '''''''''''''
            Dim strF_JOIN_ACCT As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblF_JOIN_ACCT"), Label).Text
            Dim strACCT_STATE As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblACCT_STATE"), Label).Text
            Dim strActive As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("chActive"), CheckBox).Checked
            ''''Prachak '''''''''''''
            Me.lblKYCSEQ.Text = strKYCSEQ
            If Me.lblKYCSEQ.Text = "-1" Then Me.btDelAcc.Enabled = True Else Me.btDelAcc.Enabled = True

            ''''
            Me.ddDAcc.Enabled = True
            Me.btAddDAcc.Enabled = True
            Me.btDelDAcc.Enabled = True
            Me.ddDSource.Enabled = True
            Me.btAddDSource.Enabled = True
            Me.btDelDSource.Enabled = True
            Me.ddLAcc.Enabled = True
            Me.btAddLAcc.Enabled = True
            Me.btDelLAcc.Enabled = True
            Me.ddPAcc.Enabled = True
            Me.btAddPAcc.Enabled = True
            Me.btDelPAcc.Enabled = True

            Me.ddPSource.Enabled = True
            Me.btAddPSource.Enabled = True
            Me.btDelPSource.Enabled = True


            Me.chkBO_SELF.Enabled = True
            If Me.chkBO_SELF.Checked = True Then
                Me.btAddBo_SELF.Enabled = True
            Else
                Me.btAddBo_SELF.Enabled = False
            End If

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            hdfKYCSeq.Value = strKYCSEQ
            TxtAccNo.Text = grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text.Trim
            If grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text.Trim = "" Then
                txtAccName.Text = txtNameTh1.Text & " " & txtNameTh3.Text
            Else
                txtAccName.Text = strAccName
            End If

            '''' assign value to Active
            If strActive = True Then
                Me.lblACTIVE.Text = "Y"
            Else
                Me.lblACTIVE.Text = "N"
            End If

            If Not TxtAccNo.Text.Trim = "" Then

                If Request.QueryString("KYC") = 1 Then
                    BindingDataKYCDeposit()
                ElseIf Request.QueryString("KYC") = 2 Then
                    BindingDataKYCLoan()
                ElseIf Request.QueryString("KYC") = 3 Then
                    BindingDataKYCPN()

                Else
                    Dim intAnswerType As Integer = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblAnswerType"), Label).Text
                    ' VisbleKYC()
                    If intAnswerType = 1 Or intAnswerType = 2 Then
                        PanelDeposit.Visible = True
                        PanelLoan.Visible = False
                        PanelPN.Visible = False
                        BindingDataKYCDeposit()
                    ElseIf intAnswerType = 3 Or intAnswerType = 4 Then
                        PanelDeposit.Visible = False
                        PanelLoan.Visible = True
                        PanelPN.Visible = False
                        BindingDataKYCLoan()
                    ElseIf intAnswerType = 5 Or intAnswerType = 6 Then
                        PanelDeposit.Visible = False
                        PanelLoan.Visible = False
                        PanelPN.Visible = True
                        BindingDataKYCPN()
                    End If

                End If


            End If

            btAddBo.Text = "เพิ่มข้อมูล BO ของเลขที่บัญชี " & grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text.Trim
            lbOfAcc1.Text = "ของเลขที่บัญชี " & grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text.Trim
            lbOfAcc2.Text = "ของเลขที่บัญชี " & grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text.Trim
            lbOfAcc3.Text = "ของเลขที่บัญชี " & grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text.Trim

            ''''Prachak ''''''''''''''''''''''''
            lblACCT_STATE.Text = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblACCT_STATE"), Label).Text
            lblF_JOIN_ACCT.Text = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblF_JOIN_ACCT"), Label).Text
            If strF_JOIN_ACCT = "Y" Then
                Me.chkJoin_Account.Checked = True
                Me.Select_Account_For_Main(CustSeq, Me.TxtAccNo.Text)
                Me.Set_BO_set_Enable_False()
                Me.lblACCT_STATE.Text = "J"
            Else
                Me.chkJoin_Account.Checked = False
                Me.lblACCT_STATE.Text = "S"
                Me.Set_BO_set_Enable_True()
            End If
            ''''''''''''''''''''''''''''''''''''''
            chkBO_SELF.Enabled = True
            If Me.chkBO_SELF.Checked = True Then
                Me.btAddBo_SELF.Enabled = True
            Else
                Me.btAddBo_SELF.Enabled = False
            End If

            '''''''''''''''''''''''''''''''
            chkBO_SELF.Checked = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lbFLAG_SELF_BO"), Label).Text
            If Me.chkBO_SELF.Checked = True Then
                Me.btAddBo_SELF.Enabled = True
            Else
                Me.btAddBo_SELF.Enabled = False
            End If
            '''''''''''''''''''''''''''''''
            chkBO_OTH.Enabled = True
            chkBO_OTH.Checked = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lbFLAG_OTHP_BO"), Label).Text
            btAddBo.Enabled = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lbFLAG_OTHP_BO"), Label).Text
        End If
        If Me.chkJoin_Account.Checked = True Then
            loadBo(CInt(Me.lblHEAD_CUSTSEQ.Text))
            If Me.lblHEAD_ACCT_BO_OTH.Text = "Y" Then Me.chkBO_OTH.Checked = True Else Me.chkBO_OTH.Checked = False
            '  If Me.lblHEAD_ACCT_BO_SELF.Text = "Y" Then Me.chkBO_SELF.Checked = True Else Me.chkBO_SELF.Checked = False
            Me.chkBO_SELF.Enabled = False : Me.chkBO_OTH.Enabled = False
        Else
            loadBo(CustSeq)
            Me.chkBO_SELF.Enabled = True : Me.chkBO_OTH.Enabled = True
        End If


        If (Request.QueryString("KYC") = 1) Then
            loadDObj(grdDAcc)
            loadDsource(grdDSource)
        ElseIf (Request.QueryString("KYC") = 2) Then
            loadDObj(grdLAcc)
        ElseIf (Request.QueryString("KYC") = 3) Then
            loadDObj(grdPAcc)
            loadDsource(grdPSource)
        End If
        ' VisbleKYC()
    End Sub

    Protected Sub grdShowAccount_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdShowAccount.SelectedIndexChanging

        intBeforeItemIndex = grdShowAccount.SelectedIndex
        'btnAdd.Visible = False
        'btnAddOld.Visible = True

        VisbleKYC()
    End Sub

    Private Sub resetData()
        'gvUserRight.DataSource = dsUserRight.Tables("sUserRight")
        'gvUserRight.DataBind()
        grdShowAccount.SelectedIndex = -1
        Me.TxtAccNo.Text = ""
        Me.txtAccName.Text = ""
        Me.Clear_Head_Account()
        Me.Set_BO_set_Enable_True()
        Me.chkJoin_Account.Checked = False
        Me.lblACCT_STATE.Text = "S"
        hdfKYCSeq.Value = Nothing
        Me.TxtAccNo.Enabled = True
        Me.txtAccName.Enabled = True
        Me.btnSave.Visible = False
        Me.btAddAcc.Enabled = True
        Me.btDelAcc.Enabled = False
        Me.btnPOP_CBS.Enabled = True
        ''''end offer Script''''
        btAddBo.Text = "เพิ่มข้อมูล BO"
        lbOfAcc1.Text = ""
        lbOfAcc2.Text = ""
        lbOfAcc3.Text = ""

        'chkSelf_BO.Enabled = True
        'chkSelf_BO.Checked = False
        'chkObOther.Enabled = True
        'chkObOther.Checked = False

        btAddBo.Enabled = False
        ClearFieldBo()
        If (Request.QueryString("KYC") = 1) Then
            clearDAcc()
            clearDSource()
        ElseIf (Request.QueryString("KYC") = 2) Then
            clearLAcc()
        ElseIf (Request.QueryString("KYC") = 3) Then
            clearPAcc()
            clearPSource()
        End If
        ''''end offer Script''''
        Me.TxtAccNo.Focus()
        clearPanel()
    End Sub

    Sub Set_BO_set_Enable_False()
        Me.btnPOP_CBS.Visible = True
        Me.btAddBo.Enabled = False
        Me.chkBO_OTH.Enabled = False
        Me.chkBO_SELF.Enabled = False
        Me.btEditBo.Enabled = False
        Me.btDelBo.Enabled = False
    End Sub

    Sub Set_BO_set_Enable_True()
        Me.btnPOP_CBS.Visible = False
        Me.btAddBo.Enabled = True
        Me.chkBO_OTH.Enabled = True : Me.chkBO_OTH.Checked = False
        Me.chkBO_SELF.Enabled = True : Me.chkBO_SELF.Checked = False
        Me.btEditBo.Enabled = True
        Me.btDelBo.Enabled = True
    End Sub

    Private Sub clearPanel()
        If PanelDeposit.Visible = True Then
            clearDataInControl(PanelDeposit)
        ElseIf PanelLoan.Visible = True Then
            clearDataInControl(PanelLoan)
        ElseIf PanelPN.Visible = True Then
            clearDataInControl(PanelPN)
        End If

    End Sub

    Private Sub clearDataInControl(ByVal plControl As Panel)
        Dim pl As Panel = plControl

        For Each i As Control In pl.Controls

            If TypeOf (i) Is CheckBox Then
                Dim chk As CheckBox = CType(i, CheckBox)
                chk.Checked = False
            End If

            If TypeOf (i) Is TextBox Then
                Dim txt As TextBox = CType(i, TextBox)
                txt.Text = ""
            End If

            If TypeOf (i) Is DropDownList Then
                Dim ddl As DropDownList = CType(i, DropDownList)
                ddl.SelectedIndex = 0
            End If

        Next

    End Sub

    Protected Sub txtDValue_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDValue.TextChanged
        Try
            If Not txtDValue.Text = "" Then
                clsMoney = New clsMoney
                If clsMoney.insertComma(txtDValue.Text.Trim) = True Then
                    txtDValue.Text = clsMoney.insertComma(txtDValue.Text.Trim)
                    Image2.ImageUrl = "~/img/icon/accept.png"
                    Image2.Visible = True
                End If
                clsMoney = Nothing
            End If
        Catch ex As Exception
            condition = False
            Image2.ImageUrl = "~/img/icon/cancel.png"
            Image2.Visible = True
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & clsMoney.getStrMsg & "')", True)

        End Try
    End Sub

    Protected Sub ddlDApprove_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDApprove.SelectedIndexChanged
        If ddlDApprove.SelectedIndex = 0 Then
            txtDApproveNo.Enabled = False
            txtApprovePassword.Enabled = False
            txtDApproveNo.Text = ""
            txtApprovePassword.Text = ""
        Else
            If ddlDApprove.SelectedValue = 1 Then
                txtDApproveNo.Enabled = False
                txtApprovePassword.Enabled = False
                txtDApproveNo.Text = ""
                txtApprovePassword.Text = ""
            Else
                txtDApproveNo.Enabled = True
                txtApprovePassword.Enabled = True
            End If
        End If

    End Sub

    Sub setApprove()
        Try
            ddlDApprove.SelectedIndex = 0
            txtDApproveNo.Text = ""

            clsDateFormat = New clsDateFormat
            txtDApproveDate.Text = clsDateFormat.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, Now.Date)
            clsDateFormat = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub btnSaveAcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDeleteAcc.Click

        If (grdShowAccount.SelectedIndex > -1) Then
            Dim strAccountNo As String = grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text.Trim
            If Not strAccountNo.Trim = "" Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & "ไม่สามารถลบได้" & "')", True)
                Exit Sub
            End If

            Dim strBranch As String = grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(7).Text.Trim
            Dim strUpdateby As String = grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(6).Text.Trim
            If Not (strUpdateby.Substring(0, 3) = "ETL") Then
                If Not (clsSessionMenuRight.getBranchCode = strBranch) Then

                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & "ไม่สามารถลบข้อมูลต่างสาขาได้" & "')", True)
                    Exit Sub
                End If
            End If


            KYCEntity = New KYCEntities
            KYCEntity.Connection.Open()
            Using transaction As System.Data.Common.DbTransaction = KYCEntity.Connection.BeginTransaction()
                Try
                    Dim strKYCSEQ As String = CType(grdShowAccount.Rows(grdShowAccount.SelectedIndex).FindControl("lblKYCSeq"), Label).Text

                    'delete account
                    Dim qry = (From R_KYC In KYCEntity.RKYC Where R_KYC.CUSTSEQ = CustSeq And R_KYC.KYCSEQ = strKYCSEQ).ToList
                    KYCEntity.DeleteObject(qry(0))
                    KYCEntity.SaveChanges()


                    Dim intCountComplete As Integer = 0
                    For i As Integer = 0 To ds.Tables("rkyc").Rows.Count - 1
                        If Not strKYCSEQ = ds.Tables("rkyc").Rows(i).Item("KYCSEQ").ToString Then
                            If ds.Tables("rkyc").Rows(i).Item("KYCCOMPLETE").ToString.Trim = "N" Then
                                intCountComplete += 1
                            End If
                        End If
                    Next
                    Dim updateCust = (From Cust In KYCEntity.MCUSTOMER
                             Where Cust.CUSTSEQ = CustSeq
                             Select Cust).First()
                    If Request.QueryString("KYC") = 1 Then
                        If intCountComplete = 0 Then
                            updateCust.DEPD = "Y"
                        Else
                            updateCust.DEPD = "N"
                        End If
                    ElseIf Request.QueryString("KYC") = 2 Then
                        If intCountComplete = 0 Then
                            updateCust.DEPL = "Y"
                        Else
                            updateCust.DEPL = "N"
                        End If
                    ElseIf Request.QueryString("KYC") = 3 Then
                        If intCountComplete = 0 Then
                            updateCust.DEPP = "Y"
                        Else
                            updateCust.DEPP = "N"
                        End If
                    End If
                    transaction.Commit()
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & "ทำการลบเสร็จเรียบร้อยแล้ว" & "')", True)

                Catch ex As Exception
                    transaction.Rollback()
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('Error : " & ex.ToString & " Error message : " & ex.Message & "')", True)
                End Try

            End Using

            KYCEntity.SaveChanges()
            loadKYCAccount()
            grdShowAccount.SelectedIndex = -1
            KYCEntity = Nothing
        Else
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & "ไม่สามารถลบได้" & "')", True)

        End If

    End Sub

    Private Function chkDataKYC(ByVal strKyc As String) As Boolean
        Dim blnChk As Boolean = True
        Dim intAns1 As Integer = 0
        Dim intAns2 As Integer = 0
        Dim intSource As Integer = 0

        If strKyc = 1 Then
            intAns1 = 0
            intAns2 = 0
            If chkDAcc1.Checked = True Then
                intAns1 += 1
            End If
            If chkDAcc2.Checked = True Then
                intAns1 += 1
            End If
            If chkDAcc3.Checked = True Then
                intAns1 += 1
            End If
            If chkDAcc4.Checked = True Then
                intAns1 += 1
            End If
            If chkDAcc5.Checked = True Then
                intAns1 += 1
            End If
            If chkDSource1.Checked = True Then
                intAns2 += 1
            End If
            If chkDSource2.Checked = True Then
                intAns2 += 1
            End If
            If chkDSource3.Checked = True Then
                intAns2 += 1
            End If
            If chkDSource4.Checked = True Then
                intAns2 += 1
            End If
            If chkDSource5.Checked = True Then
                intAns2 += 1
            End If
            If chkDSource6.Checked = True Then
                intAns2 += 1
            End If

            If intAns1 = 0 Or intAns2 = 0 Or ddlDDeposit.SelectedIndex = 0 Or ddlDMoney.SelectedIndex = 0 Then
                blnChk = False
            Else
                blnChk = True 'ถือว่าทำ KYC สมบูรณ์แล้ว
            End If


        ElseIf strKyc = 2 Then
            intAns1 = 0
            If chkLAcc1.Checked = True Then
                intAns1 += 1
            End If
            If chkLAcc2.Checked = True Then
                intAns1 += 1
            End If
            If chkLAcc3.Checked = True Then
                intAns1 += 1
            End If
            If chkLAcc4.Checked = True Then
                intAns1 += 1
            End If
            If chkLAcc5.Checked = True Then
                intAns1 += 1
            End If
            If chkLAcc6.Checked = True Then
                intAns1 += 1
            End If
            If chkLAcc7.Checked = True Then
                intAns1 += 1
            End If
            If chkLAcc8.Checked = True Then
                intAns1 += 1
            End If
            If chkLAcc9.Checked = True Then
                intAns1 += 1
            End If
            If chkLAcc10.Checked = True Then
                intAns1 += 1
            End If
            If intAns1 = 0 Then
                blnChk = False
            Else
                blnChk = True 'ถือว่าทำ KYC สมบูรณ์แล้ว
            End If
        ElseIf strKyc = 3 Then
            intAns1 = 0
            intSource = 0
            If chkPAcc1.Checked = True Then
                intAns1 += 1
            End If
            If chkPAcc2.Checked = True Then
                intAns1 += 1
            End If
            If chkPAcc3.Checked = True Then
                intAns1 += 1
            End If
            If chkPAcc4.Checked = True Then
                intAns1 += 1
            End If
            If chkPAcc5.Checked = True Then
                intAns1 += 1
            End If

            If chkPSource1.Checked = True Then
                intSource += 1
            End If
            If chkPSource2.Checked = True Then
                intSource += 1
            End If
            If chkPSource3.Checked = True Then
                intSource += 1
            End If
            If chkPSource4.Checked = True Then
                intSource += 1
            End If
            If chkPSource5.Checked = True Then
                intSource += 1
            End If
            If chkPSource6.Checked = True Then
                intSource += 1
            End If

            If intAns1 = 0 Or intSource = 0 Or ddlPDeposit.SelectedIndex = 0 Or ddlPMoney.SelectedIndex = 0 Then
                blnChk = False
            Else
                blnChk = True 'ถือว่าทำ KYC สมบูรณ์แล้ว
            End If
        End If
        Return blnChk

    End Function

    Protected Sub chkExpire_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkExpire_None.CheckedChanged
        If chkExpire_None.Checked = True Then
            txtEvExpire.Text = "31/12/9999"
            txtEvExpire1.Text = "31/12/9999"
        End If
    End Sub

    Protected Sub btAddBo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddBo.Click
        Try

            If Trim(TxtAccNo.Text) = "" Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกเลขที่บัญชีก่อนทำการเพิ่ม BO')", True)
                Exit Sub
            End If
            ClearFieldBo()
            grdBo.DataSource = ds.Tables("MCUST_BO_ACCT")
            grdBo.DataBind()
            Me.lblCount_grdBo.Text = ds.Tables("MCUST_BO_ACCT").Rows.Count
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btEditNation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btEditNation.Click
        Try
            Dim index As Integer = grdAddrNation.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกประเทศที่ต้องการแก้ไขก่อน')", True)
                Exit Sub
            Else

                '''''validate '''''''''''''''
                If Me.Validate_Address_Nation() = False Then Exit Sub
                '''''''''''''''''
                Dim dTable() As DataRow
                '''''เพิ่มข้อมูลที่อยู่ '''''''''''''''''''''''''
                Me.Update_Address_36(CustSeq, CType(grdAddrNation.Rows(grdAddrNation.SelectedIndex).FindControl("lbSEQ_Nation"), Label).Text)
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                Dim strQry As String = "SEQ = " & CType(grdAddrNation.Rows(grdAddrNation.SelectedIndex).FindControl("lbSEQ_Nation"), Label).Text
                dTable = ds.Tables("MCUST_NATION").Select(strQry)

                dTable(0)("ADDRESS_1") = txtADDRESS_1_Nation.Text
                dTable(0)("ADDRESS_2") = txtADDRESS_2_Nation.Text
                dTable(0)("PHONE1") = txtPHONE1_Nation.Text
                dTable(0)("PHONE2") = txtPHONE2_Nation.Text
                dTable(0)("PHONE3") = txtPHONE3_Nation.Text
                dTable(0)("FAX") = txtFAX_Nation.Text
            End If
            ClearFieldNation()
            grdAddrNation.DataSource = ds.Tables("MCUST_NATION")
            grdAddrNation.DataBind()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btEditBo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btEditBo.Click
        Try

            Dim index As Integer = grdBo.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือก BO ที่ต้องการแก้ไขก่อน')", True)
                Exit Sub
            End If
            ClearFieldBo()
            grdBo.DataSource = ds.Tables("MCUST_BO_ACCT")
            grdBo.DataBind()
            Me.lblCount_grdBo.Text = ds.Tables("MCUST_BO_ACCT").Rows.Count

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btDelBo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelBo.Click
        Try

            Dim index As Integer = grdBo.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือก BO ที่ต้องการลบก่อน')", True)
                Exit Sub
            Else
                ds.Tables("MCUST_BO_ACCT").Rows(grdBo.SelectedIndex).Delete()
            End If

            grdBo.DataSource = ds.Tables("MCUST_BO_ACCT")
            grdBo.DataBind()
            Me.lblCount_grdBo.Text = ds.Tables("MCUST_BO_ACCT").Rows.Count
            ClearFieldBo()

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                Page.GetType(), _
                                                "clientScript", _
                                                "alert('" + ex.Message.Replace("'", "") + "')", _
                                                True)
        End Try
    End Sub

    Protected Sub btAddAcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddAcc.Click

        Dim maxSeq As Int32
        Dim cls As New clsAccount
        Dim result As Boolean = True
        Dim intANSWERTYPE As Integer = 0

        If Request.QueryString("KYC") = 1 Then
            intANSWERTYPE = 1
        ElseIf Request.QueryString("KYC") = 2 Then
            intANSWERTYPE = 3
        ElseIf Request.QueryString("KYC") = 3 Then
            intANSWERTYPE = 5
        ElseIf Request.QueryString("KYC") = 4 Then
            intANSWERTYPE = 0
        End If

        If Validate_Account_Before_Add_To_grid() = False Then Exit Sub


        If Request.QueryString("KYC") = 1 Or Request.QueryString("KYC") = 3 Then

            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''' ถ้าเป็นตั๋วสัญญาใช้เงินจะไม่มีรูปแบบการตรวจเลขที่บัญชี ยกเว้นต้องเป็นตัวเลขเท่านั้น ''''''''''''''''''''''
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            If txtAccName.Text = "" Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัญชีไม่ถูกต้อง');", True)
                result = False
                Me.TxtAccNo.Focus()
                Exit Sub
            Else
                If Not IsNumeric(TxtAccNo.Text) Then
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัญชีไม่ถูกต้อง');", True)
                    result = False
                    Me.TxtAccNo.Focus()
                    Exit Sub
                End If
            End If
        End If
        '''''''''''''''''''''''''''''''''''''''''''''''

        If ds.Tables("RKYC").Rows.Count = 0 Then
            '' ''maxSeq = 1     เลิกใช้
            If Not ds.Tables("RKYC").Columns.Contains("AccountNO") Then ds.Tables("RKYC").Columns.Add("AccountNO")
            If Not ds.Tables("RKYC").Columns.Contains("ACCOUNTNAME") Then ds.Tables("RKYC").Columns.Add("ACCOUNTNAME")
            If Not ds.Tables("RKYC").Columns.Contains("ANSWERTYPE") Then ds.Tables("RKYC").Columns.Add("ANSWERTYPE")
            If Not ds.Tables("RKYC").Columns.Contains("KYCSEQ") Then ds.Tables("RKYC").Columns.Add("KYCSEQ")
            If Not ds.Tables("RKYC").Columns.Contains("KYCCOMPLETE") Then ds.Tables("RKYC").Columns.Add("KYCCOMPLETE")
            If Not ds.Tables("RKYC").Columns.Contains("APPROVECODE") Then ds.Tables("RKYC").Columns.Add("APPROVECODE")
            If Not ds.Tables("RKYC").Columns.Contains("APPROVENO") Then ds.Tables("RKYC").Columns.Add("APPROVENO")
            If Not ds.Tables("RKYC").Columns.Contains("UPDATEBY") Then ds.Tables("RKYC").Columns.Add("UPDATEBY")
            If Not ds.Tables("RKYC").Columns.Contains("BRANCHCODE") Then ds.Tables("RKYC").Columns.Add("BRANCHCODE")
            If Not ds.Tables("RKYC").Columns.Contains("FLAG_SELF_BO") Then ds.Tables("RKYC").Columns.Add("FLAG_SELF_BO")
            If Not ds.Tables("RKYC").Columns.Contains("FLAG_OTHP_BO") Then ds.Tables("RKYC").Columns.Add("FLAG_OTHP_BO")
            ''''Prachak Nov 10, 2014 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            If Not ds.Tables("RKYC").Columns.Contains("F_JOIN_ACCT") Then ds.Tables("RKYC").Columns.Add("F_JOIN_ACCT")
            If Not ds.Tables("RKYC").Columns.Contains("ACCT_STATE") Then ds.Tables("RKYC").Columns.Add("ACCT_STATE")
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            If Not ds.Tables("RKYC").Columns.Contains("ACTIVE") Then ds.Tables("RKYC").Columns.Add("ACTIVE")
        Else
            ''''เลิกใช้
            '' ''Dim maxRow() As DataRow
            '' ''Dim strQry As String = "KYCSEQ = MAX(KYCSEQ)"
            '' ''maxRow = ds.Tables("RKYC").Select(strQry)
            '' ''maxSeq = maxRow(0)("KYCSEQ") + 1
        End If

        Dim dTable As DataRow = ds.Tables("RKYC").NewRow
        Dim strUserName As String = clsSessionMenuRight.getUserName
        Dim strBranchCode As String = clsSessionMenuRight.getBranchCode

        dTable("AccountNO") = TxtAccNo.Text
        dTable("ACCOUNTNAME") = txtAccName.Text
        dTable("ANSWERTYPE") = intANSWERTYPE    ''''ลอกมาจาก Sub loadKYCAccount()
        '' ''dTable("KYCSEQ") = maxSeq  ''''เลิกใช้
        dTable("KYCSEQ") = -1       ''''ถ้าเป็น record ใหม่ให้เป็น -1
        dTable("KYCCOMPLETE") = "N"
        dTable("APPROVECODE") = 2   ''''1=รออนุมติ,2=อนุมัติทำธุรกรรม,3=ไม่อนุมัติทำธุรกรรม
        dTable("APPROVENO") = ""    ''''txtDApproveNo.Text.Trim
        dTable("UPDATEBY") = strUserName
        dTable("BRANCHCODE") = strBranchCode
        dTable("FLAG_SELF_BO") = False
        dTable("FLAG_OTHP_BO") = False
        dTable("F_JOIN_ACCT") = Me.lblF_JOIN_ACCT.Text
        dTable("ACCT_STATE") = Me.lblACCT_STATE.Text
        dTable("ACTIVE") = True
        ds.Tables("RKYC").Rows.Add(dTable)

        grdShowAccount.DataSource = ds.Tables("RKYC")
        grdShowAccount.DataBind()
        Me.lblCount_Show_ACCT.Text = ds.Tables("RKYC").Rows.Count

        resetData()
    End Sub

    Sub SelectData_To_grid_grdCo_Account()
        ' --------- ค้นหา customer ที่ใช้บัญชีร่วม ---------

        Dim dt As New DataTable
        grdCo_Account.DataSource = New DataTable()
        grdCo_Account.DataBind()

        ViewState("grdCo_Account") = Nothing

        If ViewState("grdCo_Account") Is Nothing Then
            dt.Columns.Add(New DataColumn("ACCOUNT_NO"))
            dt.Columns.Add(New DataColumn("ACCOUNT_NAME"))
            dt.Columns.Add(New DataColumn("CUSTSEQ"))
            dt.Columns.Add(New DataColumn("CUST_NAME"))
            dt.Columns.Add(New DataColumn("KYCDATE"))
        Else
            dt = ViewState("grdCo_Account")
        End If



        Dim qry_cust = From cust In KYCEntity.MCUSTOMER
                       Join rkyc In KYCEntity.RKYC
                         On cust.CUSTSEQ Equals (rkyc.CUSTSEQ)
                      Where rkyc.ACCOUNTNO = TxtAccNo.Text
                     Select cust.CUSTSEQ,
                            cust.THFIRSTNAME,
                            cust.THLASTNAME,
                            rkyc.ACCOUNTNO,
                            rkyc.ACCOUNTNAME,
                            rkyc.KYCDATE

        If qry_cust.Count() > 0 Then
            Me.lblHead_Grid_Co_Acct.Visible = True
            Me.lblHead_Grid_Co_Acct.Text = "รายชื่อลูกค้าที่ใช้บัญชีร่วมกัน สำหรับบัญชีเลขที่ " & Me.TxtAccNo.Text
            For Each r In qry_cust
                Dim row = dt.NewRow()
                row("ACCOUNT_NO") = r.ACCOUNTNO
                row("ACCOUNT_NAME") = r.ACCOUNTNAME
                row("CUSTSEQ") = r.CUSTSEQ
                row("CUST_NAME") = r.THFIRSTNAME + " " + r.THLASTNAME
                row("KYCDATE") = r.KYCDATE
                dt.Rows.Add(row)
            Next

            grdCo_Account.DataSource = dt
            ViewState("grdCo_Account") = dt
        Else
            Me.lblHead_Grid_Co_Acct.Text = "" : Me.lblHead_Grid_Co_Acct.Visible = False
            grdCo_Account.DataSource = New DataTable()
        End If

        grdCo_Account.DataBind()

    End Sub

    Sub Update_Address_33(ByVal key As Integer, ByVal lvsSEQ As String)

        Dim lvsCustType As Integer = Session("KYC")
        Try

            Dim updateKYC = (From tbNname In KYCEntity.MCUST_OCCUPATION
                            Where (tbNname.CUSTSEQ = key And tbNname.SEQ = lvsSEQ)
                           Select tbNname).FirstOrDefault


            updateKYC.WORKADDR = txtWorkAddress.Text.Trim
            updateKYC.WORKMOO = txtWorkMoo.Text.Trim
            updateKYC.WORKSTREET = txtWorkStreet.Text
            updateKYC.WORKSTREETDESC = txtWorkStreet.Text
            updateKYC.WORKSOIDESC = txtWorkSoi.Text
            updateKYC.WORKBUILDING = txtWorkBuilding.Text
            updateKYC.WORKPROVINCE_CODE = ddlWorkProvice.SelectedValue

            updateKYC.WORKAMPHOR_CODE = ddlWorkAmphor.SelectedValue
            updateKYC.WORKTAMBOL_CODE = ddlWorkTambol.SelectedValue

            If Not ddlWorkProvice.SelectedItem.ToString = Nothing Then
                updateKYC.WORKPROVINCE = ddlWorkProvice.SelectedItem.ToString
            Else
                If Not ddlWorkAmphor.SelectedItem.ToString = Nothing Then
                    updateKYC.WORKAMPHOR = ddlWorkAmphor.SelectedItem.ToString
                    If Not ddlWorkTambol.SelectedItem.ToString = Nothing Then
                        updateKYC.WORKTAMBOL = ddlWorkTambol.SelectedItem.ToString
                    End If
                End If
            End If


            updateKYC.WORKZIP = txtWorkPostCode.Text
            updateKYC.WORKPHONE1 = txtWorkPhone1_1.Text
            updateKYC.WORKPHONE2 = txtWorkPhone2_2.Text
            updateKYC.WORKPHONE3 = txtWorkPhone3_3.Text
            updateKYC.WORKFAX = txtWorkFax1_1.Text
            updateKYC.CREATED_DATE = Now
            updateKYC.CREATED_BY = clsSessionMenuRight.getUserName

            KYCEntity.SaveChanges()
            ''''KYCEntity = Nothing
            clsDatabase = Nothing
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('บันทึกข้อมูลเรียบร้อย')", True)
        Catch ex As Exception
            Throw ex
        End Try


    End Sub

    Sub Delete_Address_33(ByVal key As Integer, ByVal lvsSEQ As String)

        Dim lvsCustType As Integer = Session("KYC")
        Try

            Dim updateKYC = (From tbNname In KYCEntity.MCUST_OCCUPATION
                            Where (tbNname.CUSTSEQ = key And tbNname.SEQ = lvsSEQ)
                           Select tbNname).FirstOrDefault


            updateKYC.WORKADDR = ""
            updateKYC.WORKMOO = ""
            updateKYC.WORKSTREET = ""
            updateKYC.WORKSOIDESC = ""
            ' updateKYC.WORKBUILDING = txtWorkBuilding.Text = CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWorkBuildingOccDetail"), Label).Text
            updateKYC.WORKPROVINCE_CODE = ""
            updateKYC.WORKAMPHOR_CODE = ""
            updateKYC.WORKTAMBOL_CODE = ""
            updateKYC.WORKPROVINCE = ""
            updateKYC.WORKAMPHOR = ""
            updateKYC.WORKTAMBOL = ""
            updateKYC.WORKZIP = ""
            updateKYC.WORKPHONE1 = ""
            updateKYC.WORKPHONE2 = ""
            updateKYC.WORKPHONE3 = ""
            updateKYC.WORKFAX = ""
            updateKYC.CREATED_DATE = Now
            updateKYC.CREATED_BY = clsSessionMenuRight.getUserName

            KYCEntity.SaveChanges()
            ''''KYCEntity = Nothing
            clsDatabase = Nothing
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ลบข้อมูลที่อยู่เรียบร้อยแล้ว')", True)
        Catch ex As Exception
            Throw ex
        End Try


    End Sub

    Sub Update_Address_36(ByVal key As Integer, ByVal lvsSEQ As String)


        Dim lvsCustType As Integer = Session("KYC")
        Try

            Dim updateKYC = (From tbNname In KYCEntity.MCUST_NATION
                            Where (tbNname.CUSTSEQ = key And tbNname.SEQ = lvsSEQ)
                           Select tbNname).FirstOrDefault


            updateKYC.ADDRESS_1 = txtADDRESS_1_Nation.Text.Trim
            updateKYC.ADDRESS_2 = txtADDRESS_2_Nation.Text.Trim
            updateKYC.PHONE1 = txtPHONE1_Nation.Text
            updateKYC.PHONE2 = txtPHONE2_Nation.Text
            updateKYC.PHONE3 = txtPHONE3_Nation.Text
            updateKYC.FAX = Me.txtFAX_Nation.Text

            updateKYC.CREATED_DATE = Now
            updateKYC.CREATED_BY = clsSessionMenuRight.getUserName

            KYCEntity.SaveChanges()
            ''''KYCEntity = Nothing
            clsDatabase = Nothing
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('บันทึกข้อมูลเรียบร้อย')", True)
        Catch ex As Exception
            Throw ex
        End Try


    End Sub

    Sub Delete_Address_36(ByVal key As Integer, ByVal lvsSEQ As String)

        Dim lvsCustType As Integer = Session("KYC")
        Try

            Dim updateKYC = (From tbNname In KYCEntity.MCUST_NATION
                            Where (tbNname.CUSTSEQ = key And tbNname.SEQ = lvsSEQ)
                           Select tbNname).FirstOrDefault


            updateKYC.ADDRESS_1 = ""
            updateKYC.ADDRESS_2 = ""
            updateKYC.PHONE1 = ""
            updateKYC.PHONE2 = ""
            updateKYC.PHONE3 = ""
            updateKYC.FAX = ""
            updateKYC.CREATED_DATE = Now
            updateKYC.CREATED_BY = clsSessionMenuRight.getUserName

            KYCEntity.SaveChanges()
            ''''KYCEntity = Nothing
            clsDatabase = Nothing
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ลบข้อมูลที่อยู่เรียบร้อยแล้ว')", True)
        Catch ex As Exception
            Throw ex
        End Try


    End Sub

    Protected Sub btEditOccDetail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btEditOccDetail.Click
        Try


            Dim index As Integer = grdOccDetail.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกอาชีพที่ต้องการแก้ไขก่อน')", True)
                Exit Sub
            Else
                ''''''Validate Data ''''''''''''''''''''''''''''''''''''
                If Me.Validate_Occupation_Address = False Then Exit Sub

                ''''''Update Data '''''''''''''''''''''''''''''''''''''''
                Me.Update_Address_33(CustSeq, CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbSEQ_OccDetail"), Label).Text)

                Dim dTable() As DataRow
                Dim strQryRow As String = "SEQ = " & CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbSEQ_OccDetail"), Label).Text
                dTable = ds.Tables("MCUST_OCCUPATION").Select(strQryRow)

                dTable(0)("WORKADDR") = txtWorkAddress.Text
                dTable(0)("WORKMOO") = txtWorkMoo.Text
                dTable(0)("WORKSTREETDESC") = txtWorkStreet.Text
                dTable(0)("WORKSOIDESC") = txtWorkSoi.Text
                dTable(0)("WORKBUILDING") = txtWorkBuilding.Text
                dTable(0)("WORKPROVINCE_CODE") = ddlWorkProvice.SelectedValue
                dTable(0)("WORKAMPHOR_CODE") = ddlWorkAmphor.SelectedValue
                dTable(0)("WORKTAMBOL_CODE") = ddlWorkTambol.SelectedValue
                dTable(0)("WORKPROVINCE") = ddlWorkProvice.SelectedItem
                dTable(0)("WORKAMPHOR") = ddlWorkAmphor.SelectedItem
                dTable(0)("WORKTAMBOL") = ddlWorkTambol.SelectedItem
                dTable(0)("WORKZIP") = txtWorkPostCode.Text
                dTable(0)("WORKPHONE1") = txtWorkPhone1_1.Text
                dTable(0)("WORKPHONE2") = txtWorkPhone2_2.Text
                dTable(0)("WORKPHONE3") = txtWorkPhone3_3.Text
                dTable(0)("WORKFAX") = txtWorkFax1_1.Text
            End If

            grdOccDetail.DataSource = ds.Tables("MCUST_OCCUPATION")
            grdOccDetail.DataBind()

            grdOccDetail.SelectedIndex = -1
            Me.ClearField_OccDetail()


        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub chkBO_OTH_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkBO_OTH.CheckedChanged
        If Trim(TxtAccNo.Text) = "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกเลขที่บัญชีก่อน')", True)
            Exit Sub
        End If

        If chkBO_OTH.Checked = True Then
            btAddBo.Enabled = True
        Else
            btAddBo.Enabled = False
        End If

        Dim dTable() As DataRow
        Dim strQry As String = "AccountNO = '" & grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text & "'"
        dTable = ds.Tables("RKYC").Select(strQry)
        dTable(0)("FLAG_OTHP_BO") = chkBO_OTH.Checked
        grdShowAccount.DataSource = ds.Tables("RKYC")
        grdShowAccount.DataBind()
    End Sub

    Protected Sub btnPOP_CBS_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPOP_CBS.Click
        Me.Select_Main_Account()
    End Sub

    Sub Select_Main_Account()
        If clsValid.CheckNull(Me.TxtAccNo) = False Then Exit Sub
        If CheckAccount_NO(Me.TxtAccNo) = False Then Exit Sub
        Me.Select_Account_For_Main(CustSeq, Me.TxtAccNo.Text)
    End Sub

    Protected Sub grdOccDetail_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdOccDetail.RowDataBound
        If (e.Row.RowType.ToString = "DataRow") Then
            Dim lbAddr1 As Label = CType(e.Row.FindControl("lbAddr1OccDetail"), Label)
            Dim lbAddr2 As Label = CType(e.Row.FindControl("lbAddr2OccDetail"), Label)
            Dim lbWORKADDR As String = CType(e.Row.FindControl("lbWORKADDR_OccDetail"), Label).Text
            Dim lbWORKMOO As String = CType(e.Row.FindControl("lbWORKMOO_OccDetail"), Label).Text
            Dim lbWORKSTREET As String = CType(e.Row.FindControl("lbWORKSTREET_OccDetail"), Label).Text
            Dim lbWORKSOIDESC As String = CType(e.Row.FindControl("lbWORKSOIDESC_OccDetail"), Label).Text
            Dim lbWORKSTREETDESC As String = CType(e.Row.FindControl("lbWORKSTREETDESC_OccDetail"), Label).Text
            Dim lbWORKPROVINCE As String = CType(e.Row.FindControl("lbWORKPROVINCE_OccDetail"), Label).Text
            Dim lbWORKAMPHOR As String = CType(e.Row.FindControl("lbWORKAMPHOR_OccDetail"), Label).Text
            Dim lbWORKTAMBOL As String = CType(e.Row.FindControl("lbWORKTAMBOL_OccDetail"), Label).Text
            Dim lbWORKZIP As String = CType(e.Row.FindControl("lbWORKZIP_OccDetail"), Label).Text

            Dim strAddr1 As String
            Dim strAddr2 As String

            strAddr1 = lbWORKADDR & " " & lbWORKMOO & " " & lbWORKSOIDESC & " " & lbWORKSTREETDESC  ''''แบบไม่มี WORKSTREET
            strAddr2 = lbWORKTAMBOL & " " & lbWORKAMPHOR & " " & lbWORKPROVINCE & " " & lbWORKZIP
            lbAddr1.Text = strAddr1
            lbAddr2.Text = strAddr2
        End If
    End Sub

    Protected Sub grdOccDetail_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdOccDetail.SelectedIndexChanged
        If grdOccDetail.SelectedIndex = indexGrdOccDetailBefore Then
            grdOccDetail.SelectedIndex = -1
            ClearField_OccDetail()
        Else
            Set_Occ_Enabale_True()

            txtWorkAddress.Text = CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKADDR_OccDetail"), Label).Text
            txtWorkMoo.Text = CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKMOO_OccDetail"), Label).Text
            txtWorkStreet.Text = CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKSTREETDESC_OccDetail"), Label).Text
            txtWorkSoi.Text = CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKSOIDESC_OccDetail"), Label).Text
            txtWorkBuilding.Text = CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWorkBuilding_OccDetail"), Label).Text
            loadDataAddr(CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKPROVINCE_CODE_OccDetail"), Label).Text, _
                            CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKAMPHOR_CODE_OccDetail"), Label).Text, _
                            CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKTAMBOL_CODE_OccDetail"), Label).Text, 2)

            txtWorkPostCode.Text = CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKZIP_OccDetail"), Label).Text
            txtWorkPhone1_1.Text = CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKPHONE1_OccDetail"), Label).Text
            txtWorkPhone2_2.Text = CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKPHONE2_OccDetail"), Label).Text
            txtWorkPhone3_3.Text = CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKPHONE3_OccDetail"), Label).Text
            txtWorkFax1_1.Text = CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbWORKFAX_OccDetail"), Label).Text


            Me.txtWorkAddress.Focus()
            Me.btEditOccDetail.Enabled = True
            If txtWorkAddress.Text <> "" Then
                Me.btDeleteOccDetail.Enabled = True
            Else
                Me.btDeleteOccDetail.Enabled = False
            End If
        End If
    End Sub

    Protected Sub grdOccDetail_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdOccDetail.SelectedIndexChanging
        indexGrdOccDetailBefore = grdOccDetail.SelectedIndex
    End Sub

    Protected Sub grdAddrNation_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdAddrNation.SelectedIndexChanging
        indexGrdAddrNationBefore = grdAddrNation.SelectedIndex
    End Sub

    Protected Sub grdAddrNation_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdAddrNation.SelectedIndexChanged
        If grdAddrNation.SelectedIndex = indexGrdAddrNationBefore Then
            ClearFieldNation()
        Else

            lbNATION_NAME.Text = CType(grdAddrNation.Rows(grdAddrNation.SelectedIndex).FindControl("lbNATION_NAME_InNationGrd"), Label).Text
            txtADDRESS_1_Nation.Text = CType(grdAddrNation.Rows(grdAddrNation.SelectedIndex).FindControl("lbADDRESS_1_Nation"), Label).Text
            txtADDRESS_2_Nation.Text = CType(grdAddrNation.Rows(grdAddrNation.SelectedIndex).FindControl("lbADDRESS_2_Nation"), Label).Text
            txtPHONE1_Nation.Text = CType(grdAddrNation.Rows(grdAddrNation.SelectedIndex).FindControl("lbPHONE1_Nation"), Label).Text
            txtPHONE2_Nation.Text = CType(grdAddrNation.Rows(grdAddrNation.SelectedIndex).FindControl("lbPHONE2_Nation"), Label).Text
            txtPHONE3_Nation.Text = CType(grdAddrNation.Rows(grdAddrNation.SelectedIndex).FindControl("lbPHONE3_Nation"), Label).Text
            txtFAX_Nation.Text = CType(grdAddrNation.Rows(grdAddrNation.SelectedIndex).FindControl("lbFAX_Nation"), Label).Text

            ''''''Prachak''''''
            Me.txtADDRESS_1_Nation.Focus()
            Me.btEditNation.Enabled = True
            If txtADDRESS_1_Nation.Text <> "" Then
                Me.btDeleteNation.Enabled = True
            Else
                Me.btDeleteNation.Enabled = False
            End If
        End If
    End Sub

    Protected Sub grdBo_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdBo.SelectedIndexChanging
        indexGrdBoBefore = grdBo.SelectedIndex
    End Sub

    Protected Sub grdBo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdBo.SelectedIndexChanged
        lbSELECTBO.Text = CStr(indexGrdBoBefore)
        If grdBo.SelectedIndex = indexGrdBoBefore Then
            ClearFieldBo()
        Else
            lbACCOUNTNO.Text = CType(grdBo.Rows(grdBo.SelectedIndex).FindControl("lbACCOUNTNO_Bo"), Label).Text
            lbCIF_NO.Text = CType(grdBo.Rows(grdBo.SelectedIndex).FindControl("lbCIF_NO_Bo"), Label).Text
            lbUNIQUEID.Text = CType(grdBo.Rows(grdBo.SelectedIndex).FindControl("lbUNIQUEID_Bo"), Label).Text
            lbPASSPORT_NO.Text = CType(grdBo.Rows(grdBo.SelectedIndex).FindControl("lbPASSPORT_NO_Bo"), Label).Text
            lbTHFIRSTNAME.Text = CType(grdBo.Rows(grdBo.SelectedIndex).FindControl("lbTHFIRSTNAME_Bo"), Label).Text
            lbTHMIDNAME.Text = CType(grdBo.Rows(grdBo.SelectedIndex).FindControl("lbTHMIDNAME_Bo"), Label).Text
            lbTHLASTNAME.Text = CType(grdBo.Rows(grdBo.SelectedIndex).FindControl("lbTHLASTNAME_Bo"), Label).Text
            lbACC_OWN_RELATION.Text = CType(grdBo.Rows(grdBo.SelectedIndex).FindControl("lbACC_OWN_RELATION_Bo"), Label).Text
            lbFILTER_RESULT.Text = CType(grdBo.Rows(grdBo.SelectedIndex).FindControl("lbFILTER_RESULT_Bo"), Label).Text
            lbRISK_LEVEL.Text = CType(grdBo.Rows(grdBo.SelectedIndex).FindControl("lbRISK_LEVEL_Bo"), Label).Text
            lbSEQ.Text = CType(grdBo.Rows(grdBo.SelectedIndex).FindControl("lbSEQ_Bo"), Label).Text

            Me.btDelBo.Enabled = True
        End If
    End Sub

    Protected Sub chActiveBO_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rowTable As Int32
        For rowTable = 0 To grdBo.Rows.Count - 1
            With ds.Tables("MCUST_BO_ACCT")
                .Rows(rowTable).Item("ACTIVE") = CType(grdBo.Rows(rowTable).FindControl("chActiveBO"), CheckBox).Checked
            End With
        Next
        grdBo.DataSource = ds.Tables("MCUST_BO_ACCT")
        grdBo.DataBind()
        Me.lblCount_grdBo.Text = ds.Tables("MCUST_BO_ACCT").Rows.Count
    End Sub

    Protected Sub btDelAcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelAcc.Click
        Try


            Dim index As Integer = grdShowAccount.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกบัญชีที่ต้องการลบก่อน')", True)
                Exit Sub
            Else
                ds.Tables("RKYC").Rows(grdShowAccount.SelectedIndex).Delete()
                If Me.lblKYCSEQ.Text <> "-1" Then
                    Me.Delete_RKYC_AcctNo(CustSeq, Me.TxtAccNo.Text)
                End If
                Me.chkJoin_Account.Enabled = True
            End If

            grdShowAccount.DataSource = ds.Tables("RKYC")
            grdShowAccount.DataBind()
            Me.lblCount_Show_ACCT.Text = ds.Tables("RKYC").Rows.Count
            resetData()


            ''''ลบข้อมูลออกจากหน้าจอ''''''''''''
            If ds.Tables.Contains("MCUST_BO_ACCT") Then
                ds.Tables.Remove("MCUST_BO_ACCT")
            End If
            Me.grdBo.DataBind()
            Me.lblCount_grdBo.Text = "0"
            Me.chkBO_SELF.Checked = False : Me.chkBO_OTH.Enabled = False
            Me.chkBO_OTH.Checked = False

            ''''ลบข้อมูลออกจากหน้าจอ''''''''''''
            Me.lblHead_Grid_Co_Acct.Text = "" : Me.lblHead_Grid_Co_Acct.Visible = False
            Me.grdCo_Account.DataSource = Nothing
            Me.grdCo_Account.DataBind()
            ''''''''''''''''''''''''''''''''''''''''''''''''''

            ''''ลบข้อมูลออกจากหน้าจอ''''''''''''
            If ds.Tables.Contains("MCUST_DEPOSIT_OBJ") Then
                ds.Tables.Remove("MCUST_DEPOSIT_OBJ")
            End If
            Me.grdDAcc.DataBind()
            Me.grdLAcc.DataBind()
            Me.grdPAcc.DataBind()
            ''''Grid Row Count 
            Me.lblCount_grdDAcc.Text = 0
            Me.lblCount_grdLAcc.Text = 0
            Me.lblCount_grdPAcc.Text = 0
            ''''''''''''''''''''''''''''''''''''''''''''''
            If ds.Tables.Contains("MCUST_DEPOSIT_SOURCE") Then
                ds.Tables.Remove("MCUST_DEPOSIT_SOURCE")
            End If
            Me.grdDSource.DataBind()
            Me.grdPSource.DataBind()
            ''''Grid Row Count 
            Me.lblCount_grdDSource.Text = 0
            Me.lblCount_grdPSource.Text = 0
            ''''''''''''''''''''''''''''''''''''''''''''''

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try


    End Sub

    Protected Sub chActiveOccDetail_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rowTable As Int32
        For rowTable = 0 To grdOccDetail.Rows.Count - 1
            With ds.Tables("MCUST_OCCUPATION")
                .Rows(rowTable).Item("ACTIVE") = CType(grdOccDetail.Rows(rowTable).FindControl("chActiveOccDetail"), CheckBox).Checked
            End With
        Next
        grdOccDetail.DataSource = ds.Tables("MCUST_OCCUPATION")
        grdOccDetail.DataBind()
    End Sub

    Protected Sub chActive_Nation_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rowTable As Int32
        For rowTable = 0 To grdAddrNation.Rows.Count - 1
            With ds.Tables("MCUST_NATION")
                .Rows(rowTable).Item("ACTIVE") = CType(grdAddrNation.Rows(rowTable).FindControl("chActive_Nation"), CheckBox).Checked
            End With
        Next
        grdAddrNation.DataSource = ds.Tables("MCUST_NATION")
        grdAddrNation.DataBind()
    End Sub

    Protected Sub chActive_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rowTable As Int32
        For rowTable = 0 To grdShowAccount.Rows.Count - 1
            With ds.Tables("RKYC")
                .Rows(rowTable).Item("ACTIVE") = CType(grdShowAccount.Rows(rowTable).FindControl("chActive"), CheckBox).Checked
            End With
        Next
        grdShowAccount.DataSource = ds.Tables("RKYC")
        grdShowAccount.DataBind()
    End Sub

    Protected Sub chkBO_SELF_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkBO_SELF.CheckedChanged
        If Trim(TxtAccNo.Text) = "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกเลขที่บัญชีก่อน')", True)
            Exit Sub
        End If
        '''' Added on Dec 03, 2014 ''''''''''
        If Me.chkBO_SELF.Checked = True Then
            Me.btAddBo_SELF.Enabled = True
        Else
            Me.btAddBo_SELF.Enabled = False
        End If
        '''''''''''''''''''''''''''''''''''''

        Dim dTable() As DataRow
        Dim strQry As String = "AccountNO = '" & grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text & "'"
        dTable = ds.Tables("RKYC").Select(strQry)
        dTable(0)("FLAG_SELF_BO") = chkBO_SELF.Checked
        grdShowAccount.DataSource = ds.Tables("RKYC")
        grdShowAccount.DataBind()
    End Sub

#Region ""
    Sub Select_Account_For_Main(ByVal lvsCustSeq As Integer, ByVal lvsAcctNo As String)

        Dim dtbMCus As DataTable = New DataTable
        Dim lvsSQL As String
        Dim lvsAccount_Name As String = ""
        Dim lvsAleart As String = ""


        lvsSQL = ""
        lvsSQL += "     SELECT DISTINCT TO_CHAR(RR.ACCOUNTNO) AS ACCOUNTNO,     "
        lvsSQL += "            RR.ACCOUNTNAME,                                  "
        lvsSQL += "            RR.ACCT_STATE,                                   "
        lvsSQL += "            RR.CUSTSEQ,                                      "
        lvsSQL += "            MM.THFIRSTNAME || ' ' || THLASTNAME AS NAME_T,   "
        lvsSQL += "            RR.FLAG_SELF_BO,                                 "
        lvsSQL += "            RR.FLAG_OTHP_BO                                  "
        lvsSQL += "       FROM RKYC RR,                                         "
        lvsSQL += "            MCUSTOMER MM                                     "
        lvsSQL += "      WHERE RR.CUSTSEQ = MM.CUSTSEQ                          "
        lvsSQL += "        AND RR.ACCOUNTNO = '" & lvsAcctNo & "'               "
        lvsSQL += "        AND RR.CUSTSEQ <> '" & lvsCustSeq & "'               "
        lvsSQL += "        AND (RR.ACCT_STATE = 'M'                             "
        lvsSQL += "             OR ACCT_STATE = 'S')                            "
        lvsSQL += "   ORDER BY RR.CUSTSEQ                                       "
        dtbMCus = clsDatabase.QueryDataTable(lvsSQL)
        If (dtbMCus.Rows.Count <> 0) Then
            If Not IsDBNull(dtbMCus.Rows(0)("ACCOUNTNO")) Then Me.lblHead_ACCT_NO.Text = dtbMCus.Rows(0)("ACCOUNTNO")
            If Not IsDBNull(dtbMCus.Rows(0)("ACCOUNTNAME")) Then Me.lblHead_ACCT_Name.Text = dtbMCus.Rows(0)("ACCOUNTNAME")
            If Not IsDBNull(dtbMCus.Rows(0)("ACCOUNTNAME")) Then Me.txtAccName.Text = dtbMCus.Rows(0)("ACCOUNTNAME")
            If Not IsDBNull(dtbMCus.Rows(0)("ACCT_STATE")) Then Me.lblHEAD_ACCT_STATE.Text = dtbMCus.Rows(0)("ACCT_STATE")
            If Not IsDBNull(dtbMCus.Rows(0)("CUSTSEQ")) Then Me.lblHEAD_CUSTSEQ.Text = dtbMCus.Rows(0)("CUSTSEQ")
            If Not IsDBNull(dtbMCus.Rows(0)("NAME_T")) Then Me.lblHEAD_CUST_NAME.Text = dtbMCus.Rows(0)("NAME_T")
            If Not IsDBNull(dtbMCus.Rows(0)("FLAG_SELF_BO")) Then Me.lblHEAD_ACCT_BO_SELF.Text = dtbMCus.Rows(0)("FLAG_SELF_BO")
            If Not IsDBNull(dtbMCus.Rows(0)("FLAG_OTHP_BO")) Then Me.lblHEAD_ACCT_BO_OTH.Text = dtbMCus.Rows(0)("FLAG_OTHP_BO")
            Me.lblHEAD_ACCT_STATE_N.Text = "M"

            If Me.lblHEAD_ACCT_BO_SELF.Text = "Y" Then
                Me.chkBO_SELF.Checked = True
            Else
                Me.chkBO_SELF.Checked = False
            End If

            If Me.lblHEAD_ACCT_BO_OTH.Text = "Y" Then
                Me.chkBO_OTH.Checked = True
            Else
                Me.chkBO_OTH.Checked = False
            End If


            '''''''''''''''''''''''''''''''''''''''''''''
            Me.SelectData_To_grid_grdCo_Account()
            '''''''''''''''''''''''''''''''''''''''''''''
            If Me.btnPOP_CBS.Visible = True Then Me.btnPOP_CBS.Visible = False
        Else
            lvsAleart = "ข้อมูลไม่ถูกต้อง  ! ไม่มีบัญชีเจ้าของที่ต้องการร่วม"
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('" & lvsAleart & "');", True)
            Exit Sub
        End If

    End Sub
#End Region

#Region "validate"

    Function CheckAccount_NO(ByVal lvsAcctno As Object) As Boolean
        Dim cls As New clsAccount
        Dim result As Boolean = True

        If Request.QueryString("KYC") = 1 Then

            If cls.chkAccountDisposit(TxtAccNo.Text.Trim) = False Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัญชีไม่ถูกต้อง');", True)
                result = False
                lvsAcctno.Focus()

            End If

        ElseIf Request.QueryString("KYC") = 2 Then

            If cls.chkAccountLoan(TxtAccNo.Text.Trim) = False Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัญชีไม่ถูกต้อง');", True)
                result = False
                lvsAcctno.Focus()

            End If
        End If

        Return result

    End Function


    Function Validate_Account_Before_Add_To_grid() As Boolean

        Dim dtbMCus As DataTable = New DataTable
        Dim lvsSQL As String
        Dim lvsAccount_Name As String = ""
        Dim lvsAleart As String = ""


        Validate_Account_Before_Add_To_grid = False

        If Me.CheckAccount_NO(Me.TxtAccNo) = False Then Exit Function
        If clsValid.CheckNull(Me.txtAccName) = False Then Exit Function


        ''''''''Validate ข้อมูลซ้ำ''''''''''''''''''
        Dim mAccountNo As String = ""
        For Each rowid As GridViewRow In grdShowAccount.Rows

            mAccountNo = rowid.Cells(1).Text
            If mAccountNo = TxtAccNo.Text.Trim Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาเลือกบัญชีอื่น');", True)
                TxtAccNo.Focus()
                Exit Function
            End If

        Next

        ''''''ตรวจสอบว่าถ้าเป็นบัญชีร่วมแล้วต้องหา Head ถ้าไม่มีให้แจ้ง Error ว่า "ไม่มีบัญชีของเจ้าของบัญชีที่เป็น Head" '''''''''''''''''''''''
        If Me.chkJoin_Account.Checked = True Then
            If lblHead_ACCT_Name.Text = "" Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรูณาป้อนขัอมูลบัญชีร่วมให้ครบถ้วน');", True)
                TxtAccNo.Focus()
                Exit Function
            End If

        End If
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        lvsSQL = ""
        lvsSQL += "     SELECT ACCOUNTNO,                               "
        lvsSQL += "            ACCOUNTNAME                              "
        lvsSQL += "       FROM RKYC                                     "
        lvsSQL += "      WHERE ACCOUNTNO = '" & Me.TxtAccNo.Text & "'   "
        dtbMCus = clsDatabase.QueryDataTable(lvsSQL)

        If (dtbMCus.Rows.Count <> 0) Then

            If Not IsDBNull(dtbMCus.Rows(0)("ACCOUNTNAME")) Then lvsAccount_Name = dtbMCus.Rows(0)("ACCOUNTNAME")

            If chkJoin_Account.Checked = True Then
                Validate_Account_Before_Add_To_grid = True
                txtAccName.Text = lvsAccount_Name
                Exit Function
            Else
                lvsAleart = "ข้อมูลซ้ำ! กับบัญชีชื่อ -" & lvsAccount_Name & "- กรุณาเลือกเลขที่บัญชีอื่นหรือเลือเป็นบัญชีร่วม"
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('" & lvsAleart & "');", True)
                Exit Function
            End If

        Else
            Validate_Account_Before_Add_To_grid = True
        End If
        Validate_Account_Before_Add_To_grid = True
    End Function

    Function Validate_Occupation_Address() As Boolean

        Validate_Occupation_Address = False

        If clsValid.CheckNull(Me.txtWorkAddress) = False Then Exit Function

        'If ddlWorkProvice.SelectedIndex <= 0 Then
        '    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert(' กรูณาเลือกจังหวัด');", True)
        '    ddlWorkProvice.Focus()
        '    Exit Function
        'Else

        '    If ddlWorkAmphor.SelectedValue <= 0 Then
        '        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert(' กรูณาเลือกอำเภอ/แขวง');", True)
        '        ddlWorkAmphor.Focus()
        '        Exit Function
        '    Else
        '        If ddlWorkTambol.SelectedValue <= 0 Then
        '            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert(' กรูณาเลือกตำบล/เขต');", True)
        '            ddlWorkTambol.Focus()
        '            Exit Function
        '        End If
        '    End If
        'End If
        '''''''''''''''''''''''''''''
        Validate_Occupation_Address = True
    End Function

    Function Validate_Address_Nation() As Boolean

        Validate_Address_Nation = False

        If clsValid.CheckNull(Me.txtADDRESS_1_Nation) = False Then Exit Function
        If clsValid.CheckNull(Me.txtADDRESS_2_Nation) = False Then Exit Function
        '''''''''''''''''''''''''''''
        Validate_Address_Nation = True
    End Function


    Function Validate_For_All() As Boolean
        Dim lvsOK As String

        Validate_For_All = False

        If Me.chkBO_SELF.Checked = False And Me.chkBO_OTH.Checked = False Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage",
                          "window.alert('กรูณาเลือกเป็นผู้รับผลประโยชน์เองหรือมีผู้รับผลประโยชน์อื่น');", True)
            Me.chkBO_SELF.Focus()
            Exit Function
        End If

        If CInt(Me.lblCount_grdBo.Text) = 0 Then
            ScriptManager.RegisterStartupScript(Page,
                          Page.GetType(), "alertMessage", "window.alert('กรูณาป้อนข้อมูลผู้รับผลประโยชน์');", True)
            Me.chkBO_OTH.Focus()
            Exit Function
        End If

        '''''''''''''''''''''''''''''''''''''''''''''''''''''
        '''''''''''''''''''''''''''''''''''''''''''''''''''''
        '''''''ตรวจสอบผู้รับผลประโยชน์เอง ''''''''''''''''''''''''''
        Dim mIDCard_No As String = ""

        If Me.chkBO_SELF.Checked = False Then

            For Each rowid As GridViewRow In Me.grdBo.Rows
                mIDCard_No = CType(rowid.FindControl("lbUNIQUEID_Bo"), Label).Text
                If mIDCard_No = txtUniqueID.Text.Trim Then
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลขัดแย้งกัน ! กรูณาเลือก-เป็นผู้รับผลประโยชน์เอง');", True)
                    Me.chkBO_SELF.Focus()
                    Exit Function
                End If

            Next
        Else

            lvsOK = "N"
            For Each rowid As GridViewRow In Me.grdBo.Rows
                mIDCard_No = CType(rowid.FindControl("lbUNIQUEID_Bo"), Label).Text
                If mIDCard_No = txtUniqueID.Text.Trim Then
                    lvsOK = "Y"
                End If
            Next

            If lvsOK = "N" Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลขัดแย้งกัน ! กรูณาเพิ่มข้อมูลผู้รับผลประโยชน์เอง');", True)
                Me.btAddBo_SELF.Focus()
                Exit Function
            End If

        End If

        ''''''''''''''''''''''''''''''''''''''''''
        ''''''''''''''''''''''''''''''''''''''''''
        ''''''''''''''''''''''''''''''''''''''''''
        '''''''ตรวจสอบผู้รับผลประโยชน์อื่น '''''''''''''''
        If Me.chkBO_OTH.Checked = False Then
            mIDCard_No = ""
            For Each rowid As GridViewRow In Me.grdBo.Rows
                mIDCard_No = CType(rowid.FindControl("lbUNIQUEID_Bo"), Label).Text
                If mIDCard_No <> txtUniqueID.Text.Trim Then
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลขัดแย้งกัน ! กรูณาเลือก-เป็นผู้รับผลประโยชน์อื่น');", True)
                    Me.chkBO_SELF.Focus()
                    Exit Function
                End If
            Next

        Else
            lvsOK = "N"

            For Each rowid As GridViewRow In Me.grdBo.Rows
                mIDCard_No = CType(rowid.FindControl("lbUNIQUEID_Bo"), Label).Text
                If mIDCard_No <> txtUniqueID.Text.Trim Then
                    lvsOK = "Y"
                    Exit For
                End If
            Next

            If lvsOK = "N" Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลขัดแย้งกัน ! กรูณาเพิ่มข้อมูลผู้รับผลประโยชน์อื่่น');", True)
                Me.btAddBo_SELF.Focus()
                Exit Function
            End If

        End If




        Validate_For_All = True

    End Function


#End Region

#Region "Save Data Deposit"

    Protected Sub Save_to_RKYC(ByVal key As Integer)

        Dim dtRKYC = ds.Tables("RKYC")

        'Try

        '    ''''offer Script''''
        '    Dim mKYCSEQ As Integer
        '    ''''End offer Script''''

        '    Dim CUSTTYPE As Int32 = Request.QueryString("KYC")
        '    Dim dtRKYC = ds.Tables("RKYC")

        '    Dim DeletedQuery = (From m In KYCEntity.RKYC
        '                       Where m.CUSTSEQ = key _
        '                         And m.CUSTTYPE = CUSTTYPE
        '                      Select m).ToList

        '    If DeletedQuery.Count > 0 Then
        '        For i As Integer = 0 To DeletedQuery.Count - 1
        '            KYCEntity.RKYC.DeleteObject(DeletedQuery(i))
        '        Next i
        '    End If

        '    For Each dr As DataRow In dtRKYC.Rows

        '        '''' Collect data from data set'''''
        '        Dim mAccountNo = dr("ACCOUNTNO")
        '        Dim mACCOUNTNAME = dr("ACCOUNTNAME")
        '        Dim mANSWERTYPE = dr("ANSWERTYPE")
        '        ''''offer Script''''
        '        If dr("KYCSEQ") = -1 Then
        '            Dim sql As String = "select " &
        '                System.Configuration.ConfigurationSettings.AppSettings("SequentRKYC_S") &
        '                " from dual"  ''''OLD

        '            ''''Dim sql As String = "select " & System.Configuration.ConfigurationManager.AppSettings("SequentRKYC_S") & " from dual"
        '            ds.Tables.Add(clsDatabase.QueryDataSet(sql, "GENKYC").Tables("GENKYC").Copy)
        '            mKYCSEQ = ds.Tables("GENKYC").Rows(0)("NEXTVAL")
        '        Else
        '            mKYCSEQ = dr("KYCSEQ")
        '        End If
        '        ''''End offer Script''''
        '        Dim mKYCCOMPLETE = dr("KYCCOMPLETE").ToString() ''''ข้อมูลเก่ามีค่า Null ต้องดัก
        '        Dim mAPPROVECODE = IIf(dr("APPROVECODE").ToString() = "", 0, dr("APPROVECODE"))   ''''ข้อมูลเก่ามีค่า Null ต้องดัก
        '        Dim mAPPROVENO = dr("APPROVENO").ToString() ''''ข้อมูลเก่ามีค่า Null ต้องดัก
        '        Dim mUPDATEBY = dr("UPDATEBY").ToString()   ''''ข้อมูลเก่ามีค่า Null ต้องดัก
        '        Dim mBRANCHCODE = dr("BRANCHCODE").ToString()   ''''ข้อมูลเก่ามีค่า Null ต้องดัก
        '        Dim mFLAG_SELF_BO = IIf(dr("FLAG_SELF_BO") = True, "Y", "N")
        '        Dim mFLAG_OTHP_BO = IIf(dr("FLAG_OTHP_BO") = True, "Y", "N")
        '        Dim mACTIVE = IIf(dr("ACTIVE") = True, "Y", "N")

        '        '''''''LINQ Start here '''''''''''''
        '        Dim newRKYC As New RKYC
        '        newRKYC.CUSTSEQ = key
        '        newRKYC.KYCSEQ = mKYCSEQ
        '        newRKYC.CUSTTYPE = CUSTTYPE
        '        newRKYC.ACCOUNTNO = mAccountNo
        '        newRKYC.ACCOUNTNAME = mACCOUNTNAME
        '        newRKYC.KYCCOMPLETE = mKYCCOMPLETE

        '        newRKYC.APPROVECODE = Nothing
        '        newRKYC.APPROVENAME = Nothing
        '        newRKYC.APPROVENO = Nothing
        '        newRKYC.APPROVEDATE = Nothing

        '        If Session("KYC") = 1 Then
        '            newRKYC.DEPUPDATE = "D"
        '        ElseIf Session("KYC") = 2 Then
        '            newRKYC.DEPUPDATE = "L"
        '        ElseIf Session("KYC") = 3 Then
        '            newRKYC.DEPUPDATE = "P"
        '        ElseIf Session("KYC") = 5 Then
        '            newRKYC.DEPUPDATE = "N"
        '        End If

        '        newRKYC.UPDATEBY = mUPDATEBY
        '        newRKYC.BRANCHCODE = mBRANCHCODE
        '        newRKYC.FLAG_SELF_BO = mFLAG_SELF_BO
        '        newRKYC.FLAG_OTHP_BO = mFLAG_OTHP_BO
        '        newRKYC.ACTIVE = mACTIVE
        '        newRKYC.CREATEDATE = Now
        '        newRKYC.CREATEBY = clsSessionMenuRight.getUserName

        '        KYCEntity.AddToRKYC(newRKYC)

        '    Next
        '    KYCEntity.SaveChanges()

        'Catch ex As Exception
        '    Throw ex

        'End Try

    End Sub

    Protected Sub Save_to_MCUST_BO_Deposit(ByVal key As Integer, ByVal acctNo As String)

        Dim mBO_Acctno As String = ""
        Dim mBO_CIF_NO As String = ""
        Dim mBO_UNIQUEID As String = ""
        Dim mBO_PASSPORT_NO As String = ""
        Dim mBO_THFIRSTNAME As String = ""
        Dim mBO_THMIDNAME As String = ""
        Dim mBO_THLASTNAME As String = ""
        Dim mBO_ACC_OWN_RELATION As String = ""
        Dim mBO_FILTER_RESULT As String = ""
        Dim mBO_RISK_LEVEL As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''
        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_BO_ACCT
                               Where m.CUSTSEQ = key _
                                 And m.ACCOUNTNO = TxtAccNo.Text _
                                 And m.CUSTTYPE = lvsCustType
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_BO_ACCT.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdBo.Rows
                Dim newCust_BO As New MCUST_BO_ACCT

                ''''get values from Gridview '''''''
                mBO_Acctno = CType(lvsRow_No.FindControl("lbACCOUNTNO_Bo"), Label).Text
                mBO_CIF_NO = CType(lvsRow_No.FindControl("lbCIF_NO_Bo"), Label).Text
                mBO_UNIQUEID = CType(lvsRow_No.FindControl("lbUNIQUEID_Bo"), Label).Text
                mBO_PASSPORT_NO = CType(lvsRow_No.FindControl("lbPASSPORT_NO_Bo"), Label).Text
                mBO_THFIRSTNAME = CType(lvsRow_No.FindControl("lbTHFIRSTNAME_Bo"), Label).Text
                mBO_THMIDNAME = CType(lvsRow_No.FindControl("lbTHMIDNAME_Bo"), Label).Text
                mBO_THLASTNAME = CType(lvsRow_No.FindControl("lbTHLASTNAME_Bo"), Label).Text
                mBO_ACC_OWN_RELATION = CType(lvsRow_No.FindControl("lbACC_OWN_RELATION_Bo"), Label).Text
                mBO_FILTER_RESULT = CType(lvsRow_No.FindControl("lbFILTER_RESULT_Bo"), Label).Text
                mBO_RISK_LEVEL = CType(lvsRow_No.FindControl("lbRISK_LEVEL_Bo"), Label).Text
                If (CType(lvsRow_No.Cells(8).FindControl("chActiveBO"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_BO.CUSTSEQ = key
                newCust_BO.CUSTTYPE = Session("KYC")
                newCust_BO.SEQ = lvsRow_No.RowIndex + 1
                newCust_BO.ACCOUNTNO = mBO_Acctno.Trim
                newCust_BO.CIF_NO = mBO_CIF_NO.Trim
                newCust_BO.UNIQUEID = mBO_UNIQUEID.Trim
                newCust_BO.PASSPORT_NO = mBO_PASSPORT_NO.Trim
                newCust_BO.THFIRSTNAME = mBO_THFIRSTNAME.Trim
                newCust_BO.THMIDNAME = mBO_THMIDNAME.Trim
                newCust_BO.THLASTNAME = mBO_THLASTNAME.Trim
                newCust_BO.ACC_OWN_RELATION = mBO_ACC_OWN_RELATION.Trim
                newCust_BO.FILTER_RESULT = mBO_FILTER_RESULT.Trim
                newCust_BO.RISK_LEVEL = CInt(mBO_RISK_LEVEL.Trim)
                newCust_BO.ACTIVE = chActive
                newCust_BO.CREATED_DATE = Now
                newCust_BO.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_BO_ACCT(newCust_BO)

            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try
    End Sub


    Protected Sub Save_to_MCUST_LOAN_OBJ(ByVal key As Integer, ByVal acctNo As String)

        Dim mLO_Acctno As String = ""
        Dim mLO_Objective As String = ""
        Dim mLO_Remarks As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''
        If lvsCustType <> 2 Then Exit Sub
        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_DEPOSIT_OBJ
                               Where m.CUSTSEQ = key _
                                 And m.ACCOUNTNO = acctNo _
                                 And m.CUSTTYPE = lvsCustType
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_DEPOSIT_OBJ.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdLAcc.Rows
                Dim newCust_Dept_Obj As New MCUST_DEPOSIT_OBJ

                ''''get values from Gridview '''''''

                mLO_Acctno = lvsRow_No.Cells(1).Text : If mLO_Acctno = "&nbsp;" Then mLO_Acctno = ""
                mLO_Objective = lvsRow_No.Cells(2).Text : If mLO_Objective = "&nbsp;" Then mLO_Objective = ""
                mLO_Remarks = lvsRow_No.Cells(3).Text : If mLO_Remarks = "&nbsp;" Then mLO_Remarks = ""
                If (CType(lvsRow_No.Cells(4).FindControl("chActiveLAcc"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_Dept_Obj.CUSTSEQ = key
                newCust_Dept_Obj.CUSTTYPE = Session("KYC")
                newCust_Dept_Obj.SEQ = lvsRow_No.RowIndex + 1
                newCust_Dept_Obj.ACCOUNTNO = mLO_Acctno.Trim
                newCust_Dept_Obj.OBJECTIVE = mLO_Objective.Trim
                newCust_Dept_Obj.REMARKS = mLO_Remarks.Trim
                newCust_Dept_Obj.ACTIVE = chActive
                newCust_Dept_Obj.CREATED_DATE = Now
                newCust_Dept_Obj.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_DEPOSIT_OBJ(newCust_Dept_Obj)

            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try
    End Sub


#End Region

#Region "Validate "

#End Region

    Protected Sub btDeleteOccDetail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDeleteOccDetail.Click
        Try

            Dim index As Integer = grdOccDetail.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกอาชีพที่ต้องการแก้ไขก่อน')", True)
                Exit Sub
            Else
                Me.Delete_Address_33(CustSeq, CType(grdOccDetail.Rows(grdOccDetail.SelectedIndex).FindControl("lbSEQ_OccDetail"), Label).Text)
            End If

            Me.loadOcc()

            grdOccDetail.SelectedIndex = -1
            Me.ClearField_OccDetail()

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub


    Protected Sub btDeleteNation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDeleteNation.Click
        Try

            Dim index As Integer = Me.grdAddrNation.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกสัญชาติที่ต้องการแก้ไขก่อน')", True)
                Exit Sub
            Else
                Me.Delete_Address_36(CustSeq, CType(grdAddrNation.Rows(grdAddrNation.SelectedIndex).FindControl("lbSEQ_Nation"), Label).Text)
            End If

            Me.loadAddrNation()

            grdAddrNation.SelectedIndex = -1
            ClearFieldNation()

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

#Region "Update KYC Address"

    Function Validate_Address_KYC() As Boolean

        Validate_Address_KYC = False

        If clsValid.CheckNull(Me.txtKYC_ADDR) = False Then Exit Function
        If clsValid.CheckNull(Me.txtKYC_MOO) = False Then Exit Function
        '''''''''''''''''''''''''''''
        Validate_Address_KYC = True
    End Function

    Protected Sub ddlKYC_PROVINCE_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlKYC_PROVINCE.SelectedIndexChanged
        Dim clsDropDown As New clsMasterDropDown

        If Not ddlKYC_PROVINCE.SelectedIndex = 0 Then
            clsDropDown.setAmphor(ddlKYC_AMPHOR, ProviceCode:=ddlKYC_PROVINCE.SelectedValue)
        Else
            ddlKYC_AMPHOR.Items.Clear()
            Me.ddlKYC_TAMBOL.Items.Clear()
        End If
    End Sub

    Protected Sub ddlKYC_MPHOR_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlKYC_AMPHOR.SelectedIndexChanged
        Dim clsDropDown As New clsMasterDropDown

        If Not ddlKYC_AMPHOR.SelectedIndex = 0 Then
            clsDropDown.setTambol(ddlKYC_TAMBOL, AmphorCode:=ddlKYC_AMPHOR.SelectedValue)
        Else
            ddlKYC_TAMBOL.Items.Clear()
        End If
    End Sub


    Private Sub save_UPDATE_KYC_ADDRESS()
        Try

            Dim strTempProvince As String = ""
            Dim strTempTambol As String = ""
            Dim strTempAmphor As String = ""

            If Validate_Address_KYC() = False Then Exit Sub

            Dim updateCust = (From Cust In KYCEntity.MCUSTOMER
                            Where Cust.CUSTSEQ = CustSeq
                            Select Cust).First()
            ''''Prachak '''''''''''''''''''''''''''''''''''

            updateCust.KYC_BUILDING = Me.txtKYC_BUILDING.Text
            updateCust.KYC_FLOOR = Me.txtKYC_FLOOR.Text
            updateCust.KYC_DIV_CONT = Me.txtKYC_DIV_CONT.Text
            updateCust.KYC_ADDR = Me.txtKYC_ADDR.Text
            updateCust.KYC_MOO = Me.txtKYC_MOO.Text
            updateCust.KYC_SOIDESC = Me.txtKYC_SOIDESC.Text
            updateCust.KYC_STREETDESC = Me.txtKYC_STREETDESC.Text
            updateCust.KYC_LOCALITY = Me.txtKYC_LOCALITY.Text
            updateCust.KYC_ZIP = Me.txtKYC_ZIP.Text
            updateCust.KYC_PHONE1 = Me.txtKYC_PHONE1.Text
            updateCust.KYC_PHONE2 = Me.txtKYC_PHONE2.Text
            updateCust.KYC_PHONE3 = Me.txtKYC_PHONE3.Text
            updateCust.KYC_FAX = Me.txtKYC_FAX.Text

            If ddlKYC_TAMBOL.Items.Count = 0 Then
                strTempTambol = "-"
            Else
                If (ddlKYC_TAMBOL.SelectedIndex = 0) Then
                    strTempTambol = "-"
                Else
                    strTempTambol = ddlKYC_TAMBOL.SelectedItem.ToString()
                End If
            End If

            If ddlKYC_AMPHOR.Items.Count = 0 Then
                strTempAmphor = "-"
            Else
                If (ddlKYC_AMPHOR.SelectedIndex = 0) Then
                    strTempAmphor = "-"
                Else
                    strTempAmphor = ddlKYC_AMPHOR.SelectedItem.ToString()
                End If
            End If

            If ddlKYC_PROVINCE.Items.Count = 0 Then
                strTempProvince = "-"
            Else
                If (ddlKYC_PROVINCE.SelectedIndex = 0) Then
                    strTempProvince = "-"
                Else
                    strTempProvince = ddlKYC_PROVINCE.SelectedItem.ToString()
                End If
            End If

            updateCust.KYC_PROVINCE = ddlKYC_PROVINCE.SelectedValue
            updateCust.KYC_AMPHOR = ddlKYC_AMPHOR.SelectedValue
            updateCust.KYC_TAMBOL = ddlKYC_TAMBOL.SelectedValue

            KYCEntity.SaveChanges()
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('บันทึกข้อมูลเรียบร้อย')", True)

            ''''Prachak '''''''''''''''''''''''''''''''''''

            'updateCust.WORKNO = txtWorkAddress.Text.Trim
            'updateCust.WORKMOO = txtWorkMoo.Text.Trim
            'updateCust.WORKSTREET = txtWorkStreet.Text.Trim
            'updateCust.WORKSOIDESC = txtWorkSoi.Text.Trim
            'updateCust.WORKBUILDING = txtWorkBuilding.Text.Trim
            'updateCust.WORKPROVINCE = ddlWorkProvice.SelectedValue
            'updateCust.WORKAMPHOR = ddlWorkAmphor.SelectedValue
            'updateCust.WORKTAMBOL = ddlWorkTambol.SelectedValue
            'updateCust.WORKPHONE1 = txtWorkPhone1_1.Text.Trim
            'updateCust.WORKPHONE2 = txtWorkPhone2_2.Text.Trim
            'updateCust.WORKPHONE3 = txtWorkPhone3_3.Text.Trim
            'updateCust.WORKFAX = txtWorkFax1_1.Text.Trim
            'updateCust.WORKZIP = txtWorkPostCode.Text.Trim


            'If ddlWorkTambol.Items.Count = 0 Then
            '    strTempTambol = "-"
            'Else
            '    If (ddlWorkTambol.SelectedIndex = 0) Then
            '        strTempTambol = "-"
            '    Else
            '        strTempTambol = ddlWorkTambol.SelectedItem.ToString()
            '    End If
            'End If

            'If ddlWorkAmphor.Items.Count = 0 Then
            '    strTempAmphor = "-"
            'Else
            '    If (ddlWorkAmphor.SelectedIndex = 0) Then
            '        strTempAmphor = "-"
            '    Else
            '        strTempAmphor = ddlWorkAmphor.SelectedItem.ToString()
            '    End If
            'End If

            'If ddlWorkProvice.Items.Count = 0 Then
            '    strTempProvince = "-"
            'Else
            '    If (ddlWorkProvice.SelectedIndex = 0) Then
            '        strTempProvince = "-"
            '    Else
            '        strTempProvince = ddlWorkProvice.SelectedItem.ToString()
            '    End If
            'End If



        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub btnUPDATE_KYC_ADDRESS_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUPDATE_KYC_ADDRESS.Click
        Me.save_UPDATE_KYC_ADDRESS()
    End Sub


#End Region

#Region "clear Screen"


    Sub Initial_Screen()
        Me.Set_Occ_Enabale_False()
    End Sub

    Sub Set_Occ_Enabale_True()
        'txtWorkAddress.Enabled = True
        'txtWorkMoo.Enabled = True
        'txtWorkStreet.Enabled = True
        'txtWorkSoi.Enabled = True
        'txtWorkBuilding.Enabled = True
        'ddlWorkProvice.Enabled = True
        'ddlWorkAmphor.Enabled = True
        'ddlWorkTambol.Enabled = True
        'txtWorkPostCode.Enabled = True
        'txtWorkPhone1_1.Enabled = True
        'txtWorkPhone2_2.Enabled = True
        'txtWorkPhone3_3.Enabled = True
        'txtWorkFax1_1.Enabled = False
    End Sub

    Sub Set_Occ_Enabale_False()
        'txtWorkAddress.Enabled = False
        'txtWorkMoo.Enabled = False
        'txtWorkStreet.Enabled = False
        'txtWorkSoi.Enabled = False
        'txtWorkBuilding.Enabled = False
        'ddlWorkProvice.Enabled = False
        'ddlWorkAmphor.Enabled = False
        'ddlWorkTambol.Enabled = False
        'txtWorkPostCode.Enabled = False
        'txtWorkPhone1_1.Enabled = False
        'txtWorkPhone2_2.Enabled = True
        'txtWorkPhone3_3.Enabled = True
        'txtWorkFax1_1.Enabled = False
    End Sub
#End Region

    'Protected Sub btnFiles_Import_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFiles_Import.Click
    '    'Dim row As GridViewRow = grdShowAccount.Rows(index)
    '    If Not String.IsNullOrEmpty(lbCUSTSEQ.Text) Then
    '        Try
    '            If (grdShowAccount.SelectedIndex >= -1) Then
    '                Dim accountNO As String = grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text
    '                'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Administrator/KycFileScan.aspx?CUSTSEQ=" & CInt(CustSeq) & "&accountNO=" & accountNO & "','_blank','scrollbars=1,Width:1000px, Height:600px')", True)
    '                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "window.open('../Administrator/KycFileScan.aspx?CUSTSEQ=" & lbCUSTSEQ.Text & "&accountNO=" & accountNO & "','_blank','scrollbars=1,Width:800px, Height:600px')", True)
    '            End If
    '        Catch ex As Exception
    '            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & ex.Message & "')", True)
    '            condition = False
    '        End Try
    '    End If

    'End Sub

    Protected Sub chkJoin_Account_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkJoin_Account.CheckedChanged
        If Me.chkJoin_Account.Checked = True Then
            Me.lblF_JOIN_ACCT.Text = "Y"
            Me.lblACCT_STATE.Text = "J"
            Me.Set_BO_set_Enable_False()
        Else
            Me.lblF_JOIN_ACCT.Text = "N"
            Me.lblACCT_STATE.Text = "S"
            Me.Set_BO_set_Enable_True()
            Me.Clear_Head_Account()
        End If

    End Sub
    Sub Clear_Head_Account()
        Me.lblHEAD_CUSTSEQ.Text = ""
        Me.lblHead_ACCT_Name.Text = ""
        Me.lblHead_ACCT_NO.Text = ""
        Me.lblHEAD_ACCT_STATE.Text = ""

        Me.lblHEAD_CUST_NAME.Text = ""
        Me.lblHEAD_ACCT_STATE_N.Text = ""
        Me.lblHEAD_ACCT_BO_SELF.Text = ""
        Me.lblHEAD_ACCT_BO_OTH.Text = ""
    End Sub
    Private Sub SetControlAddress()
        Dim kyc = Request.QueryString("KYC")
        If (kyc = 1 OrElse kyc = 2) Then
            KYCAddress_Visable = "style=""display: block;"""
            CBSAddress_Visable = "style=""display: block;"""
        End If
        If (kyc = 3 OrElse kyc = 5) Then
            KYCAddress_Visable = "style=""display: block;"""
            CBSAddress_Visable = "style=""display: none;"""
        End If
    End Sub


#Region "สอบถามเงินฝาก"

    Function Validate_Deposit_Obj() As Boolean
        Validate_Deposit_Obj = False

        ''''''''Validate ข้อมูลซ้ำ''''''''''''''''''
        Dim mObjective As String = ""
        For Each rowIncome As GridViewRow In Me.grdDAcc.Rows
            mObjective = rowIncome.Cells(2).Text
            If mObjective = ddDAcc.SelectedItem.Text Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาเลือกวัตถุประสงค์ใหม่');", True)
                ddDAcc.Focus()
                Exit Function
            End If
        Next
        '''''''''''''''''''''''''''''
        Validate_Deposit_Obj = True
    End Function

    Protected Sub btAddDAcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddDAcc.Click
        Add_To_Grid_grdDAcc()
    End Sub

    Sub Add_To_Grid_grdDAcc()

        Try
            If Trim(TxtAccNo.Text) = "" Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกเลขที่บัญชีก่อนทำการเพิ่มข้อมูล')", True)
                Exit Sub
            End If

            If Validate_Deposit_Obj() = False Then Exit Sub

            Dim maxSeq As Int32
            If ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count = 0 Then
                maxSeq = 1
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("ACCOUNTNO") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("ACCOUNTNO")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("OBJECTIVE") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("OBJECTIVE")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("REMARKS") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("REMARKS")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("ACTIVE") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("ACTIVE")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("SEQ") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("SEQ")
            Else
                Dim maxRow() As DataRow
                Dim strQry As String = "SEQ = MAX(SEQ)"
                maxRow = ds.Tables("MCUST_DEPOSIT_OBJ").Select(strQry)
                maxSeq = maxRow(0)("SEQ") + 1
            End If
            Dim dTable As DataRow = ds.Tables("MCUST_DEPOSIT_OBJ").NewRow

            dTable("ACCOUNTNO") = TxtAccNo.Text
            dTable("OBJECTIVE") = ddDAcc.SelectedItem
            dTable("REMARKS") = txtDAccOther.Text
            dTable("SEQ") = maxSeq
            dTable("ACTIVE") = True
            ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Add(dTable)

            grdDAcc.DataSource = ds.Tables("MCUST_DEPOSIT_OBJ")
            grdDAcc.DataBind()
            ''''Grid Row Count ''''''''''''''''''''''''''''''''''''''''''''''''''
            Me.lblCount_grdDAcc.Text = ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            clearDAcc()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btDelDAcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelDAcc.Click
        Delete_gridRow_grdDAcc()
    End Sub

    Sub Delete_gridRow_grdDAcc()
        Try

            Dim index As Integer = grdDAcc.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกวัตถุประสงค์ของการเปิดบัญชีที่ต้องการลบก่อน')", True)
                Exit Sub
            Else
                ds.Tables("MCUST_DEPOSIT_OBJ").Rows(grdDAcc.SelectedIndex).Delete()
            End If

            grdDAcc.DataSource = ds.Tables("MCUST_DEPOSIT_OBJ")
            grdDAcc.DataBind()
            ''''Grid Row Count ''''''''''''''''''''''''''''''''''''''''''''''''''
            Me.lblCount_grdDAcc.Text = ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            clearDAcc()

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Private Sub loadDObj(ByVal grdObj As GridView)

        Dim clsDataTable As New clsLINQToDataTable
        Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

        If ds.Tables.Contains("MCUST_DEPOSIT_OBJ") Then
            ds.Tables.Remove("MCUST_DEPOSIT_OBJ")
        End If


        ''''Where tbl.CUSTSEQ = CustSeq And tbl.ACCOUNTNO = TxtAccNo.Text And tbl.CUSTTYPE = CUSTTYPE

        Dim qry = From tbl In KYCEntity.MCUST_DEPOSIT_OBJ
                 Where tbl.ACCOUNTNO = TxtAccNo.Text And tbl.CUSTTYPE = CUSTTYPE And tbl.CUSTSEQ = CustSeq
              Order By tbl.SEQ
                Select tbl.ACCOUNTNO,
                       tbl.OBJECTIVE,
                       tbl.REMARKS,
                       tbl.SEQ,
                       ACTIVE = If(tbl.ACTIVE = "Y", True, False)

        ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_DEPOSIT_OBJ").Copy)

        grdObj.DataSource = ds.Tables("MCUST_DEPOSIT_OBJ")
        grdObj.DataBind()
        ''''Grid Row Count ''''''''''''''''''''''''''''''''''''''''''''''''''
        Me.lblCount_grdDAcc.Text = ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count
        Me.lblCount_grdLAcc.Text = ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count
        Me.lblCount_grdPAcc.Text = ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    End Sub

    Protected Sub chActiveDAcc_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rowTable As Int32
        For rowTable = 0 To grdDAcc.Rows.Count - 1
            With ds.Tables("MCUST_DEPOSIT_OBJ")
                .Rows(rowTable).Item("ACTIVE") = CType(grdDAcc.Rows(rowTable).FindControl("chActiveDAcc"), CheckBox).Checked
            End With
        Next
        grdDAcc.DataSource = ds.Tables("MCUST_DEPOSIT_OBJ")
        grdDAcc.DataBind()
    End Sub

    Protected Sub Save_to_MCUST_OBJ_Deposit(ByVal key As Integer, ByVal acctNo As String)

        Dim mDO_Acctno As String = ""
        Dim mDO_Objective As String = ""
        Dim mDO_Remarks As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''
        If lvsCustType <> 1 Then Exit Sub
        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_DEPOSIT_OBJ
                               Where m.CUSTSEQ = key _
                                 And m.ACCOUNTNO = acctNo _
                                 And m.CUSTTYPE = lvsCustType
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_DEPOSIT_OBJ.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdDAcc.Rows
                Dim newCust_Dept_Obj As New MCUST_DEPOSIT_OBJ

                ''''get values from Gridview '''''''

                mDO_Acctno = lvsRow_No.Cells(1).Text : If mDO_Acctno = "&nbsp;" Then mDO_Acctno = ""
                mDO_Objective = lvsRow_No.Cells(2).Text : If mDO_Objective = "&nbsp;" Then mDO_Objective = ""
                mDO_Remarks = lvsRow_No.Cells(3).Text : If mDO_Remarks = "&nbsp;" Then mDO_Remarks = ""
                If (CType(lvsRow_No.Cells(4).FindControl("chActiveDAcc"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_Dept_Obj.CUSTSEQ = key
                newCust_Dept_Obj.CUSTTYPE = Session("KYC")
                newCust_Dept_Obj.SEQ = lvsRow_No.RowIndex + 1
                newCust_Dept_Obj.ACCOUNTNO = mDO_Acctno.Trim
                newCust_Dept_Obj.OBJECTIVE = mDO_Objective.Trim
                newCust_Dept_Obj.REMARKS = mDO_Remarks.Trim
                newCust_Dept_Obj.ACTIVE = chActive
                newCust_Dept_Obj.CREATED_DATE = Now
                newCust_Dept_Obj.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_DEPOSIT_OBJ(newCust_Dept_Obj)

            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try
    End Sub

    Protected Sub grdDAcc_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdDAcc.SelectedIndexChanged
        If indexGrdDAccBefore = grdDAcc.SelectedIndex Then
            grdDAcc.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdDAcc_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdDAcc.SelectedIndexChanging
        indexGrdDAccBefore = grdDAcc.SelectedIndex
    End Sub

    Private Sub clearDAcc()
        grdDAcc.SelectedIndex = -1
        ddDAcc.SelectedIndex = -1
        txtDAccOther.Text = ""
    End Sub

#End Region

#Region "แหล่งที่มาของเงินฝาก"

    Function Validate_Deposit_Source() As Boolean

        Validate_Deposit_Source = False

        ''''''''Validate ข้อมูลซ้ำ''''''''''''''''''
        Dim mObjective As String = ""
        For Each rowIncome As GridViewRow In Me.grdDSource.Rows
            mObjective = rowIncome.Cells(2).Text
            If mObjective = ddDSource.SelectedItem.Text Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาเลือกแหล่งที่มาของเงินฝากใหม่');", True)
                ddDSource.Focus()
                Exit Function
            End If
        Next
        '''''''''''''''''''''''''''''
        Validate_Deposit_Source = True
    End Function

    Protected Sub btAddDSource_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddDSource.Click
        Me.Add_To_grid_DSource()
    End Sub

    Sub Add_To_grid_DSource()

        Try

            If Me.Validate_Deposit_Source() = False Then Exit Sub

            If Trim(TxtAccNo.Text) = "" Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกเลขที่บัญชีก่อนทำการเพิ่มข้อมูล')", True)
                Exit Sub
            End If

            Dim maxSeq As Int32
            If ds.Tables("MCUST_DEPOSIT_SOURCE").Rows.Count = 0 Then
                maxSeq = 1
                If Not ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Contains("ACCOUNTNO") Then ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Add("ACCOUNTNO")
                If Not ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Contains("SOURCE_OF_M") Then ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Add("SOURCE_OF_M")
                If Not ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Contains("REMARKS") Then ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Add("REMARKS")
                If Not ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Contains("ACTIVE") Then ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Add("ACTIVE")
                If Not ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Contains("SEQ") Then ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Add("SEQ")
            Else
                Dim maxRow() As DataRow
                Dim strQry As String = "SEQ = MAX(SEQ)"
                maxRow = ds.Tables("MCUST_DEPOSIT_SOURCE").Select(strQry)
                maxSeq = maxRow(0)("SEQ") + 1
            End If
            Dim dTable As DataRow = ds.Tables("MCUST_DEPOSIT_SOURCE").NewRow

            dTable("ACCOUNTNO") = TxtAccNo.Text
            dTable("SOURCE_OF_M") = ddDSource.SelectedItem
            dTable("REMARKS") = txtDSourceOther.Text
            dTable("SEQ") = maxSeq
            dTable("ACTIVE") = True
            ds.Tables("MCUST_DEPOSIT_SOURCE").Rows.Add(dTable)

            grdDSource.DataSource = ds.Tables("MCUST_DEPOSIT_SOURCE")
            grdDSource.DataBind()
            ''''Grid Row Count ''''''''''''''''''''''''''''''''''''''''''''''''''
            Me.lblCount_grdDSource.Text = ds.Tables("MCUST_DEPOSIT_SOURCE").Rows.Count
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            clearDSource()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btDelDSource_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelDSource.Click
        Delete_gridRow_DSource()
    End Sub

    Sub Delete_gridRow_DSource()
        Try

            Dim index As Integer = grdDSource.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกแหล่งที่มาของเงินฝากที่ต้องการลบก่อน')", True)
                Exit Sub
            Else
                ds.Tables("MCUST_DEPOSIT_SOURCE").Rows(grdDSource.SelectedIndex).Delete()
            End If
            clearDSource()
            grdDSource.DataSource = ds.Tables("MCUST_DEPOSIT_SOURCE")
            grdDSource.DataBind()
            ''''Grid Row Count ''''''''''''''''''''''''''''''''''''''''''''''''''
            Me.lblCount_grdDSource.Text = ds.Tables("MCUST_DEPOSIT_SOURCE").Rows.Count
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Private Sub loadDsource(ByVal grdObj As GridView)

        Dim clsDataTable As New clsLINQToDataTable
        Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

        If ds.Tables.Contains("MCUST_DEPOSIT_SOURCE") Then
            ds.Tables.Remove("MCUST_DEPOSIT_SOURCE")
        End If

        Dim qry = From tbl In KYCEntity.MCUST_DEPOSIT_SOURCE
                 Where tbl.ACCOUNTNO = TxtAccNo.Text And tbl.CUSTTYPE = CUSTTYPE And tbl.CUSTSEQ = CustSeq
              Order By tbl.SEQ
                Select tbl.ACCOUNTNO,
                       tbl.SOURCE_OF_M,
                       tbl.REMARKS,
                       tbl.SEQ,
                       ACTIVE = If(tbl.ACTIVE = "Y", True, False)

        ds.Tables.Add(clsDataTable.LINQToDataTable(qry, "MCUST_DEPOSIT_SOURCE").Copy)
        grdObj.DataSource = ds.Tables("MCUST_DEPOSIT_SOURCE")
        grdObj.DataBind()
        Me.lblCount_grdDSource.Text = ds.Tables("MCUST_DEPOSIT_SOURCE").Rows.Count
        Me.lblCount_grdPSource.Text = ds.Tables("MCUST_DEPOSIT_SOURCE").Rows.Count

    End Sub

    Protected Sub chActiveDSource_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rowTable As Int32
        For rowTable = 0 To grdDSource.Rows.Count - 1
            With ds.Tables("MCUST_DEPOSIT_SOURCE")
                .Rows(rowTable).Item("ACTIVE") = CType(grdDSource.Rows(rowTable).FindControl("chActiveDSource"), CheckBox).Checked
            End With
        Next
        grdDSource.DataSource = ds.Tables("MCUST_DEPOSIT_SOURCE")
        grdDSource.DataBind()
        ''''Grid Row Count ''''''''''''''''''''''''''''''''''''''''''''''''''
        Me.lblCount_grdDSource.Text = ds.Tables("MCUST_DEPOSIT_SOURCE").Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    End Sub

    Protected Sub Save_to_MCUST_SOURCE_Deposit(ByVal key As Integer, ByVal acctNo As String)

        Dim mDS_Acctno As String = ""
        Dim mDS_Source As String = ""
        Dim mDS_Remarks As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''
        If lvsCustType <> 1 Then Exit Sub
        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_DEPOSIT_SOURCE
                               Where m.CUSTSEQ = key _
                                 And m.ACCOUNTNO = acctNo _
                                 And m.CUSTTYPE = lvsCustType
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_DEPOSIT_SOURCE.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdDSource.Rows
                Dim newCust_Dept_Source As New MCUST_DEPOSIT_SOURCE

                ''''get values from Gridview '''''''

                mDS_Acctno = lvsRow_No.Cells(1).Text : If mDS_Acctno = "&nbsp;" Then mDS_Acctno = ""
                mDS_Source = lvsRow_No.Cells(2).Text : If mDS_Source = "&nbsp;" Then mDS_Source = ""
                mDS_Remarks = lvsRow_No.Cells(3).Text : If mDS_Remarks = "&nbsp;" Then mDS_Remarks = ""
                If (CType(lvsRow_No.Cells(4).FindControl("chActiveDSource"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_Dept_Source.CUSTSEQ = key
                newCust_Dept_Source.CUSTTYPE = Session("KYC")
                newCust_Dept_Source.SEQ = lvsRow_No.RowIndex + 1
                newCust_Dept_Source.ACCOUNTNO = mDS_Acctno.Trim
                newCust_Dept_Source.SOURCE_OF_M = mDS_Source.Trim
                newCust_Dept_Source.REMARKS = mDS_Remarks.Trim
                newCust_Dept_Source.ACTIVE = chActive
                newCust_Dept_Source.CREATED_DATE = Now
                newCust_Dept_Source.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_DEPOSIT_SOURCE(newCust_Dept_Source)

            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try
    End Sub

    Protected Sub grdDSource_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdDSource.SelectedIndexChanged
        If indexGrdDSourceBefore = grdDSource.SelectedIndex Then
            grdDSource.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdDSource_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdDSource.SelectedIndexChanging
        indexGrdDSourceBefore = grdDSource.SelectedIndex
    End Sub

    Private Sub clearDSource()
        grdDSource.SelectedIndex = -1
        ddDSource.SelectedIndex = -1
        txtDSourceOther.Text = ""
    End Sub

#End Region

#Region "สอบถามสินเชื่อ"

    Function Validate_Row_53() As Boolean
        Validate_Row_53 = False

        ''''''''Validate ข้อมูลซ้ำ''''''''''''''''''
        Dim mIncome As String = ""
        For Each rowID As GridViewRow In grdLAcc.Rows
            mIncome = rowID.Cells(2).Text
            If mIncome = ddLAcc.SelectedItem.Text Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาเลือกแหล่งที่มาของรายได้อื่น');", True)
                ddLAcc.Focus()
                Exit Function
            End If

        Next
        '''''''''''''''''''''''''''''
        Validate_Row_53 = True
    End Function

    Protected Sub btAddLAcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddLAcc.Click
        Me.Add_To_Grid_LAcc()
    End Sub

    Sub Add_To_Grid_LAcc()
        Try
            If Trim(TxtAccNo.Text) = "" Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกเลขที่บัญชีก่อนทำการเพิ่มข้อมูล')", True)
                Exit Sub
            End If

            If Me.Validate_Row_53 = False Then Exit Sub

            Dim maxSeq As Int32
            If ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count = 0 Then
                maxSeq = 1
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("ACCOUNTNO") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("ACCOUNTNO")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("OBJECTIVE") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("OBJECTIVE")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("REMARKS") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("REMARKS")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("ACTIVE") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("ACTIVE")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("SEQ") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("SEQ")
            Else
                Dim maxRow() As DataRow
                Dim strQry As String = "SEQ = MAX(SEQ)"
                maxRow = ds.Tables("MCUST_DEPOSIT_OBJ").Select(strQry)
                maxSeq = maxRow(0)("SEQ") + 1
            End If
            Dim dTable As DataRow = ds.Tables("MCUST_DEPOSIT_OBJ").NewRow

            dTable("ACCOUNTNO") = TxtAccNo.Text
            dTable("OBJECTIVE") = ddLAcc.SelectedItem
            dTable("REMARKS") = txtLAccOther.Text
            dTable("SEQ") = maxSeq
            dTable("ACTIVE") = True
            ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Add(dTable)

            grdLAcc.DataSource = ds.Tables("MCUST_DEPOSIT_OBJ")
            grdLAcc.DataBind()
            ''''Grid Row Count ''''''''''''''''''''''''''''''''''''''''''''''''''
            Me.lblCount_grdLAcc.Text = ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            clearLAcc()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try

    End Sub

    Protected Sub btDelLAcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelLAcc.Click
        Me.Delete_GridRow_LAcc()
    End Sub

    Sub Delete_GridRow_LAcc()
        Try

            Dim index As Integer = grdLAcc.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกวัตถุประสงค์ของบัญชีสินเชื่อที่ต้องการลบก่อน')", True)
                Exit Sub
            Else
                ds.Tables("MCUST_DEPOSIT_OBJ").Rows(grdLAcc.SelectedIndex).Delete()
            End If
            grdLAcc.DataSource = ds.Tables("MCUST_DEPOSIT_OBJ")
            grdLAcc.DataBind()
            ''''Grid Row Count ''''''''''''''''''''''''''''''''''''''''''''''''''
            Me.lblCount_grdLAcc.Text = ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            clearLAcc()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try

    End Sub

    Protected Sub chActiveLAcc_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rowTable As Int32
        For rowTable = 0 To grdLAcc.Rows.Count - 1
            With ds.Tables("MCUST_DEPOSIT_OBJ")
                .Rows(rowTable).Item("ACTIVE") = CType(grdLAcc.Rows(rowTable).FindControl("chActiveLAcc"), CheckBox).Checked
            End With
        Next
        grdLAcc.DataSource = ds.Tables("MCUST_DEPOSIT_OBJ")
        grdLAcc.DataBind()
    End Sub

    Protected Sub Save_to_MCUST_OBJ_Loan(ByVal key As Integer, ByVal acctNo As String)

        Dim mDO_Acctno As String = ""
        Dim mDO_Objective As String = ""
        Dim mDO_Remarks As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''
        If lvsCustType <> 2 Then Exit Sub
        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_DEPOSIT_OBJ
                               Where m.CUSTSEQ = key _
                                 And m.ACCOUNTNO = acctNo _
                                 And m.CUSTTYPE = lvsCustType
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_DEPOSIT_OBJ.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdLAcc.Rows
                Dim newCust_Dept_Obj As New MCUST_DEPOSIT_OBJ

                ''''get values from Gridview '''''''

                mDO_Acctno = lvsRow_No.Cells(1).Text : If mDO_Acctno = "&nbsp;" Then mDO_Acctno = ""
                mDO_Objective = lvsRow_No.Cells(2).Text : If mDO_Objective = "&nbsp;" Then mDO_Objective = ""
                mDO_Remarks = lvsRow_No.Cells(3).Text : If mDO_Remarks = "&nbsp;" Then mDO_Remarks = ""
                If (CType(lvsRow_No.Cells(4).FindControl("chActiveLAcc"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_Dept_Obj.CUSTSEQ = key
                newCust_Dept_Obj.CUSTTYPE = Session("KYC")
                newCust_Dept_Obj.SEQ = lvsRow_No.RowIndex + 1
                newCust_Dept_Obj.ACCOUNTNO = mDO_Acctno.Trim
                newCust_Dept_Obj.OBJECTIVE = mDO_Objective.Trim
                newCust_Dept_Obj.REMARKS = mDO_Remarks.Trim
                newCust_Dept_Obj.ACTIVE = chActive
                newCust_Dept_Obj.CREATED_DATE = Now
                newCust_Dept_Obj.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_DEPOSIT_OBJ(newCust_Dept_Obj)

            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try
    End Sub

    Protected Sub grdLAcc_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdLAcc.SelectedIndexChanged
        If indexGrdLAccBefore = grdLAcc.SelectedIndex Then
            grdLAcc.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdLAcc_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdLAcc.SelectedIndexChanging
        indexGrdLAccBefore = grdLAcc.SelectedIndex
    End Sub

    Private Sub clearLAcc()
        grdLAcc.SelectedIndex = -1
        ddLAcc.SelectedIndex = -1
        txtLAccOther.Text = ""
    End Sub

#End Region

#Region "สอบถามตั๋วเงิน"

    Protected Sub btAddPAcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddPAcc.Click
        Me.Add_To_Grid_PAcc()
    End Sub

    Sub Add_To_Grid_PAcc()
        Try
            If Trim(TxtAccNo.Text) = "" Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกเลขที่บัญชีก่อนทำการเพิ่มข้อมูล')", True)
                Exit Sub
            End If

            Dim maxSeq As Int32
            If ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count = 0 Then
                maxSeq = 1
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("ACCOUNTNO") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("ACCOUNTNO")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("OBJECTIVE") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("OBJECTIVE")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("REMARKS") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("REMARKS")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("ACTIVE") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("ACTIVE")
                If Not ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Contains("SEQ") Then ds.Tables("MCUST_DEPOSIT_OBJ").Columns.Add("SEQ")
            Else
                Dim maxRow() As DataRow
                Dim strQry As String = "SEQ = MAX(SEQ)"
                maxRow = ds.Tables("MCUST_DEPOSIT_OBJ").Select(strQry)
                maxSeq = maxRow(0)("SEQ") + 1
            End If
            Dim dTable As DataRow = ds.Tables("MCUST_DEPOSIT_OBJ").NewRow

            dTable("ACCOUNTNO") = TxtAccNo.Text
            dTable("OBJECTIVE") = ddPAcc.SelectedItem
            dTable("REMARKS") = txtPAccOther.Text
            dTable("SEQ") = maxSeq
            dTable("ACTIVE") = True
            ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Add(dTable)

            grdPAcc.DataSource = ds.Tables("MCUST_DEPOSIT_OBJ")
            grdPAcc.DataBind()
            ''''Grid Row Count ''''''''''''''''''''''''''''''''''''''''''''''''''
            Me.lblCount_grdPAcc.Text = ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            clearPAcc()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btDelPAcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelPAcc.Click
        Delete_Grid_row_PSource()
    End Sub

    Sub Delete_Grid_row_PSource()
        Try

            Dim index As Integer = grdPAcc.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกวัตถุประสงค์ของการเปิดบัญชีที่ต้องการลบก่อน')", True)
                Exit Sub
            Else
                ds.Tables("MCUST_DEPOSIT_OBJ").Rows(grdPAcc.SelectedIndex).Delete()
            End If

            grdPAcc.DataSource = ds.Tables("MCUST_DEPOSIT_OBJ")
            grdPAcc.DataBind()
            ''''Grid Row Count ''''''''''''''''''''''''''''''''''''''''''''''''''
            Me.lblCount_grdPAcc.Text = ds.Tables("MCUST_DEPOSIT_OBJ").Rows.Count
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            clearPAcc()

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub chActivePAcc_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rowTable As Int32
        For rowTable = 0 To grdPAcc.Rows.Count - 1
            With ds.Tables("MCUST_DEPOSIT_OBJ")
                .Rows(rowTable).Item("ACTIVE") = CType(grdPAcc.Rows(rowTable).FindControl("chActivePAcc"), CheckBox).Checked
            End With
        Next
        grdPAcc.DataSource = ds.Tables("MCUST_DEPOSIT_OBJ")
        grdPAcc.DataBind()
    End Sub

    Protected Sub Save_to_MCUST_OBJ_PN(ByVal key As Integer, ByVal acctNo As String)

        Dim mDO_Acctno As String = ""
        Dim mDO_Objective As String = ""
        Dim mDO_Remarks As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''
        If lvsCustType <> 3 Then Exit Sub

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_DEPOSIT_OBJ
                               Where m.CUSTSEQ = key _
                                 And m.ACCOUNTNO = acctNo _
                                 And m.CUSTTYPE = lvsCustType
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_DEPOSIT_OBJ.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdPAcc.Rows
                Dim newCust_Dept_Obj As New MCUST_DEPOSIT_OBJ

                ''''get values from Gridview '''''''

                mDO_Acctno = lvsRow_No.Cells(1).Text : If mDO_Acctno = "&nbsp;" Then mDO_Acctno = ""
                mDO_Objective = lvsRow_No.Cells(2).Text : If mDO_Objective = "&nbsp;" Then mDO_Objective = ""
                mDO_Remarks = lvsRow_No.Cells(3).Text : If mDO_Remarks = "&nbsp;" Then mDO_Remarks = ""
                If (CType(lvsRow_No.Cells(4).FindControl("chActivePAcc"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_Dept_Obj.CUSTSEQ = key
                newCust_Dept_Obj.CUSTTYPE = Session("KYC")
                newCust_Dept_Obj.SEQ = lvsRow_No.RowIndex + 1
                newCust_Dept_Obj.ACCOUNTNO = mDO_Acctno.Trim
                newCust_Dept_Obj.OBJECTIVE = mDO_Objective.Trim
                newCust_Dept_Obj.REMARKS = mDO_Remarks.Trim
                newCust_Dept_Obj.ACTIVE = chActive
                newCust_Dept_Obj.CREATED_DATE = Now
                newCust_Dept_Obj.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_DEPOSIT_OBJ(newCust_Dept_Obj)

            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try
    End Sub

    Protected Sub grdPAcc_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdPAcc.SelectedIndexChanged
        If indexGrdPAccBefore = grdPAcc.SelectedIndex Then
            grdPAcc.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdPAcc_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdPAcc.SelectedIndexChanging
        indexGrdPAccBefore = grdPAcc.SelectedIndex
    End Sub

    Private Sub clearPAcc()
        grdPAcc.SelectedIndex = -1
        ddPAcc.SelectedIndex = -1
        txtPAccOther.Text = ""
    End Sub

#End Region

#Region "แหล่งที่มาของเงินฝาก-ตั๋วเงิน"

    Protected Sub btAddPSource_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddPSource.Click
        Me.Add_To_Grid_PN()
    End Sub

    Sub Add_To_Grid_PN()
        Try
            If Trim(TxtAccNo.Text) = "" Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกเลขที่บัญชีก่อนทำการเพิ่มข้อมูล')", True)
                Exit Sub
            End If

            Dim maxSeq As Int32
            If ds.Tables("MCUST_DEPOSIT_SOURCE").Rows.Count = 0 Then
                maxSeq = 1
                If Not ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Contains("ACCOUNTNO") Then ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Add("ACCOUNTNO")
                If Not ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Contains("SOURCE_OF_M") Then ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Add("SOURCE_OF_M")
                If Not ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Contains("REMARKS") Then ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Add("REMARKS")
                If Not ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Contains("ACTIVE") Then ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Add("ACTIVE")
                If Not ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Contains("SEQ") Then ds.Tables("MCUST_DEPOSIT_SOURCE").Columns.Add("SEQ")
            Else
                Dim maxRow() As DataRow
                Dim strQry As String = "SEQ = MAX(SEQ)"
                maxRow = ds.Tables("MCUST_DEPOSIT_SOURCE").Select(strQry)
                maxSeq = maxRow(0)("SEQ") + 1
            End If
            Dim dTable As DataRow = ds.Tables("MCUST_DEPOSIT_SOURCE").NewRow

            dTable("ACCOUNTNO") = TxtAccNo.Text
            dTable("SOURCE_OF_M") = ddPSource.SelectedItem
            dTable("REMARKS") = txtPSourceOther.Text
            dTable("SEQ") = maxSeq
            dTable("ACTIVE") = True
            ds.Tables("MCUST_DEPOSIT_SOURCE").Rows.Add(dTable)

            grdPSource.DataSource = ds.Tables("MCUST_DEPOSIT_SOURCE")
            grdPSource.DataBind()
            clearPSource()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btDelPSource_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelPSource.Click
        Me.Delete_GridRow_PSource()
    End Sub

    Sub Delete_GridRow_PSource()
        Try

            Dim index As Integer = grdPSource.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกแหล่งที่มาของเงินฝากที่ต้องการลบก่อน')", True)
                Exit Sub
            Else
                ds.Tables("MCUST_DEPOSIT_SOURCE").Rows(grdPSource.SelectedIndex).Delete()
            End If
            clearPSource()
            grdPSource.DataSource = ds.Tables("MCUST_DEPOSIT_SOURCE")
            grdPSource.DataBind()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub chActivePSource_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rowTable As Int32
        For rowTable = 0 To grdPSource.Rows.Count - 1
            With ds.Tables("MCUST_DEPOSIT_SOURCE")
                .Rows(rowTable).Item("ACTIVE") = CType(grdPSource.Rows(rowTable).FindControl("chActivePSource"), CheckBox).Checked
            End With
        Next
        grdPSource.DataSource = ds.Tables("MCUST_DEPOSIT_SOURCE")
        grdPSource.DataBind()
    End Sub

    Protected Sub Save_to_MCUST_SOURCE_PN(ByVal key As Integer, ByVal acctNo As String)

        Dim mDS_Acctno As String = ""
        Dim mDS_Source As String = ""
        Dim mDS_Remarks As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''
        If lvsCustType <> 3 Then Exit Sub
        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_DEPOSIT_SOURCE
                               Where m.CUSTSEQ = key _
                                 And m.ACCOUNTNO = acctNo _
                                 And m.CUSTTYPE = lvsCustType
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_DEPOSIT_SOURCE.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdPSource.Rows
                Dim newCust_Dept_Source As New MCUST_DEPOSIT_SOURCE

                ''''get values from Gridview '''''''
                mDS_Acctno = lvsRow_No.Cells(1).Text : If mDS_Acctno = "&nbsp;" Then mDS_Acctno = ""
                mDS_Source = lvsRow_No.Cells(2).Text : If mDS_Source = "&nbsp;" Then mDS_Source = ""
                mDS_Remarks = lvsRow_No.Cells(3).Text : If mDS_Remarks = "&nbsp;" Then mDS_Remarks = ""
                If (CType(lvsRow_No.Cells(4).FindControl("chActivePSource"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_Dept_Source.CUSTSEQ = key
                newCust_Dept_Source.CUSTTYPE = Session("KYC")
                newCust_Dept_Source.SEQ = lvsRow_No.RowIndex + 1
                newCust_Dept_Source.ACCOUNTNO = mDS_Acctno.Trim
                newCust_Dept_Source.SOURCE_OF_M = mDS_Source.Trim
                newCust_Dept_Source.REMARKS = mDS_Remarks.Trim
                newCust_Dept_Source.ACTIVE = chActive
                newCust_Dept_Source.CREATED_DATE = Now
                newCust_Dept_Source.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_DEPOSIT_SOURCE(newCust_Dept_Source)

            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try
    End Sub

    Protected Sub grdPSource_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdPSource.SelectedIndexChanged
        If indexGrdPSourceBefore = grdPSource.SelectedIndex Then
            grdPSource.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdPSource_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdPSource.SelectedIndexChanging
        indexGrdPSourceBefore = grdPSource.SelectedIndex

    End Sub

    Private Sub clearPSource()
        grdPSource.SelectedIndex = -1
        ddPSource.SelectedIndex = -1
        txtPSourceOther.Text = ""
    End Sub

#End Region

    Private Sub UpdateRKYC_HEAD_ACCT(ByVal HeadCustSEQ As Integer, ByVal acctNo As String)

        Try

            Dim updateCust = (From Cust In KYCEntity.RKYC
                             Where Cust.CUSTSEQ = HeadCustSEQ _
                               And Cust.ACCOUNTNO = acctNo
                            Select Cust).First()

            updateCust.ACCT_STATE = Me.lblHEAD_ACCT_STATE_N.Text

            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub Delete_RKYC_AcctNo(ByVal custSEQ As Integer, ByVal acctNo As String)

        Try

            Dim lvsQryforDel = (From Cust In KYCEntity.RKYC
                               Where Cust.CUSTSEQ = custSEQ _
                                 And Cust.ACCOUNTNO = acctNo
                              Select Cust).First()

            KYCEntity.RKYC.DeleteObject(lvsQryforDel)
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub btAddBo_SELF_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddBo_SELF.Click
        Dim maxSeq As Int32

        If ds.Tables("MCUST_BO_ACCT") Is Nothing Then
            Exit Sub
        ElseIf ds.Tables("MCUST_BO_ACCT").Rows.Count = 0 Then
            maxSeq = 1
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("ACCOUNTNO") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("ACCOUNTNO")
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("THFIRSTNAME") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("THFIRSTNAME")
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("THLASTNAME") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("THLASTNAME")
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("UNIQUEID") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("UNIQUEID")
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("ACC_OWN_RELATION") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("ACC_OWN_RELATION")
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("FILTER_RESULT") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("FILTER_RESULT")
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("RISK_LEVEL") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("RISK_LEVEL")
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("ACTIVE") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("ACTIVE")
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("CIF_NO") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("CIF_NO")
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("PASSPORT_NO") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("PASSPORT_NO")
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("THMIDNAME") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("THMIDNAME")
            If Not ds.Tables("MCUST_BO_ACCT").Columns.Contains("SEQ") Then ds.Tables("MCUST_BO_ACCT").Columns.Add("SEQ")
        Else
            For i As Integer = 0 To ds.Tables("MCUST_BO_ACCT").Rows.Count - 1
                If ds.Tables("MCUST_BO_ACCT").Rows(i).Item("UNIQUEID").ToString = txtUniqueID.Text Then
                    Exit Sub
                End If
            Next

            Dim maxRow() As DataRow
            Dim strQry As String = "SEQ = MAX(SEQ)"
            maxRow = ds.Tables("MCUST_BO_ACCT").Select(strQry)
            maxSeq = maxRow(0)("SEQ") + 1
        End If

        Dim mcbo As DataRow = ds.Tables("MCUST_BO_ACCT").NewRow()
        mcbo("ACCOUNTNO") = TxtAccNo.Text
        mcbo("THFIRSTNAME") = Me.txtNameTh1.Text
        mcbo("THLASTNAME") = Me.txtNameTh3.Text
        mcbo("UNIQUEID") = txtUniqueID.Text
        mcbo("ACC_OWN_RELATION") = "เจ้าของ"
        mcbo("FILTER_RESULT") = Me.lblFILTER_RESULT_CUST.Text
        mcbo("RISK_LEVEL") = Me.lblRISK_LEVEL_CUST.Text
        mcbo("ACTIVE") = True
        mcbo("CIF_NO") = ""
        mcbo("PASSPORT_NO") = ""
        mcbo("THMIDNAME") = Me.txtNameTh2.Text
        mcbo("SEQ") = maxSeq
        ds.Tables("MCUST_BO_ACCT").Rows.Add(mcbo)

        grdBo.DataSource = ds.Tables("MCUST_BO_ACCT")
        grdBo.DataBind()
        ''''Number of Rows '''''''''''''''''''''
        Me.lblCount_grdBo.Text = ds.Tables("MCUST_BO_ACCT").Rows.Count
        ''''''''''''''''''''''''''''''''''''''''
    End Sub

#Region "ที่อยูจาก Smart Card"

    Sub Find_SmartCard_for_Address(ByVal Citizen_ID As String)

        Try

            Dim dtSmartCard As DataTable = New DataTable


            lvsSQL = ""
            lvsSQL += "     SELECT HOUSE_CODE,                          "
            lvsSQL += "            HOUSE_NO,                            "
            lvsSQL += "            MOO,                                 "
            lvsSQL += "            SOI_DESC,                            "
            lvsSQL += "            STREET_DESC,                         "
            lvsSQL += "            PROVINCE_CODE,                       "
            lvsSQL += "            PROVINCE_DESC,                       "
            lvsSQL += "            AMPHUR_CODE,                         "
            lvsSQL += "            AMPHUR_DESC,                         "
            lvsSQL += "            TAMBOL_CODE,                         "
            lvsSQL += "            TAMBOL_NAME,                         "
            lvsSQL += "            DATE_LOGIN                           "
            lvsSQL += "       FROM KYCADMIN.GHB_BORAINTERFACE           "
            lvsSQL += "      WHERE CITIZEN_ID = '" & Citizen_ID & "'    "
            dtSmartCard = clsDatabase.QueryDataTable(lvsSQL)

            If (dtSmartCard.Rows.Count <> 0) Then

                If Not IsDBNull(dtSmartCard.Rows(0)("HOUSE_NO")) Then Me.txtIDC_ADDR.Text = dtSmartCard.Rows(0)("HOUSE_NO")
                If Not IsDBNull(dtSmartCard.Rows(0)("MOO")) Then Me.txtIDC_MOO.Text = dtSmartCard.Rows(0)("MOO")
                If Not IsDBNull(dtSmartCard.Rows(0)("SOI_DESC")) Then Me.txtIDC_SOIDESC.Text = dtSmartCard.Rows(0)("SOI_DESC")
                If Not IsDBNull(dtSmartCard.Rows(0)("STREET_DESC")) Then Me.txtIDC_STREETDESC.Text = dtSmartCard.Rows(0)("STREET_DESC")

                If Not IsDBNull(dtSmartCard.Rows(0)("PROVINCE_CODE")) Then
                    Me.loadDataAddr_SmartCard(dtSmartCard.Rows(0)("PROVINCE_CODE"), dtSmartCard.Rows(0)("AMPHUR_CODE"), dtSmartCard.Rows(0)("TAMBOL_CODE"))
                End If


            End If


        Catch ex As Exception
            '  Console.WriteLine("")
            ScriptManager.RegisterStartupScript(Page, Page.GetType(),
                                    "clientScript",
                                    "alert('" + ex.Message.Replace("'", "") + "')",
                                    True)

        End Try

    End Sub
#End Region
End Class



